pre-requestie for learning C...

H

Harald van Dijk

Hunh? What macro? I don't understand.

You do know that there is no keyword 'mod' in C, right? You need to spell
the operator properly, or you need to add a macro 'mod' to make your code
work. You said to add appropriate defines and #includes, and I don't see
anything that might need to be defined by the user as a macro, so if not
mod, what were you talking about?
 
A

Ahem A Rivet's Shot

James Kuyper said:
Phil Carmody wrote:
...
Given """
I simply gave up trying to write the following trivial encryption
program in Pascal:

i := 1;
while getc(c) <> ENDFILE do begin
putc(xor(c, key));
i := i mod keylen + 1
end

because I couldn't write a sensible 'xor' function. """
I hereby proclaim myself to be more intelligent than Brian
Kernighan. xor's trivial to write in Pascal, and I hardly know the
language at all. All it needs is addition and equality test
operators, and either modular reduction or an odd() predicate (which
I believe the languge does have).


That declaration would carry more weight if accompanied by actual
Pascal code for the xor function. I'm not saying whether it is or is
not possible - I don't remember enough about Pascal to judge.


I've never even known pascal, except to know enough that I never
wanted to learn any more.

Completely off the top of my head (or more, straight out of my arse):

function xor(a:integer;b:integer):integer;
var
bit : integer;
build : integer;
begin
bit:=1;
build:=0;
while a<>b do begin /* what's the <> operator in pascal? */
/* D'oh - what's the comment syntax? */
if odd(a)<>odd(b) then build:=build+bit;
bit:=bit+bit;
a:=a div 2;
b:=b div 2;
end;
xor:=build;
end;


Considerng that xor is an operation most processors can do in
hardware on at least a byte by byte basis I'm inclined to agree with Brian
Kernighan noting that the key word is "sensible".
 
P

Phil Carmody

Those were not my own words, those were clearly words that
I was quoting. Please preserve the distinction when quoting
my posts by including the markup used to denote quoted
material.

Phil
 
K

Keith Thompson

Phil Carmody said:
Those were not my own words, those were clearly words that
I was quoting. Please preserve the distinction when quoting
my posts by including the markup used to denote quoted
material.

It would help if you used a more standard markup, preceding each line
with a marker. "> " is traditional for material quoted from a
previous article. For quotations from another source, I generally
either indent or use a different marker, such as "| ". (And
non-Python programmers might not recognize the convention you're using
of """ on a line by itself.)
 
P

Phil Carmody

Keith Thompson said:
It would help if you used a more standard markup, preceding each line
with a marker. "> " is traditional for material quoted from a
previous article. For quotations from another source, I generally
either indent or use a different marker, such as "| ". (And
non-Python programmers might not recognize the convention you're using
of """ on a line by itself.)

I'm not a python programmer, '"""' has nothing to do with python,
it's just an arbitrary string which won't by default be interpreted
as text, but as markup. Was the meaning of it unclear to you? Did
you not realise it was a block quote?

Use of a line prefix rather than a block prefix would have required
on my part the insertion of characters to every line, and the possible
re-wrapping of text such that less-capable clients when replying do
not leave partial lines without the line prefix.

Preserving my markup would have required 1 less line deletion at
each end by the quoter.

If you were to have responded to my earlier post - would you
have preserved the '"""'? If so, why, and if not, why not?

Phil
 
P

Phil Carmody

Ahem A Rivet's Shot said:
Considerng that xor is an operation most processors can do in
hardware on at least a byte by byte basis I'm inclined to agree with Brian
Kernighan noting that the key word is "sensible".

If his issue was the lack of an atomic 'xor' primitive, then his
complaint should have been "because there doesn't exist an atomic
'xor' primitive", not "because I couldn't write a sensible 'xor'
function".

Phil
 
P

Pascal J. Bourguignon

Phil Carmody said:
Use of a line prefix rather than a block prefix would have required
on my part the insertion of characters to every line, and the possible
re-wrapping of text such that less-capable clients when replying do
not leave partial lines without the line prefix.

What are you talking about? You just select the block and type M-;

Even on lesser programs, you can just select the block and go to the
menu Format / Quote Level / Increase.

Preserving my markup would have required 1 less line deletion at
each end by the quoter.

If you were to have responded to my earlier post - would you
have preserved the '"""'? If so, why, and if not, why not?

Mainly because usenet conventions where establised even before
Internet existed! Therefore users are used to them and (good)
programs implement them. There's no need to invent new conventions.
 
P

Pascal J. Bourguignon

Ahem A Rivet's Shot said:
Considerng that xor is an operation most processors can do in
hardware on at least a byte by byte basis I'm inclined to agree with Brian
Kernighan noting that the key word is "sensible".

No it is not. Simply because like with C, you don't use a standard
language, you always use a specific implementation, and in specific
implementations, you are provided with all the practical features
omited by the standard.

Granted, these practical features may change from one implementation
to another, but often they do not, because in general implementers try
not to be gratuituously obnoxious to their users. This only prepares
the terrain for the next version of the standard.


And frankly, having a true string data type is worth much more than
lacking a standard xor function.
 
P

Phil Carmody

What are you talking about? You just select the block and type M-;

Let's see, shall we?
I simply gave up trying to write the following trivial encryption program in Pascal:
i := 1;
while getc(c) <> ENDFILE do begin
putc(xor(c, key));
i := i mod keylen + 1
end

because I couldn't write a sensible 'xor' function.

I feel sorry for you being both unable to write a sensible 'xor'
function and understand the quoting issue.
Even on lesser programs, you can just select the block and go to the
menu Format / Quote Level / Increase.

You are attempting to solve the wrong problem.
Mainly because usenet conventions where establised even before
Internet existed!

False. Which of the questions was that supposed to be an answer to?
Therefore users are used to them and (good)
programs implement them. There's no need to invent new conventions.

I think you'll find that people have been block quoting text
far longer than either Usenet or the internet has been around?
Ever heard of this stuff called 'paper', and the concept of
'printing'?

Phil
 
P

Pascal J. Bourguignon

Phil Carmody said:
Let's see, shall we?

I didn't write this.

I didn't write this.

I feel sorry for you being both unable to write a sensible 'xor'
function and understand the quoting issue.

You don't need to feel sorry for me.

But you still need to hone your usenet quoting skills.

You are attempting to solve the wrong problem.

Or the right problem: if your news reader doesn't implement ancestral
usenet conventions, then you should change your news reader.

False. Which of the questions was that supposed to be an answer to?

True. The usenet existed before the Internet. It ran on the various
network that existed at the time, such as uucp or bitnet. The >
quotation was an early invention, it was already there in the first
posts I saw before the Internet reached us.

I think you'll find that people have been block quoting text
far longer than either Usenet or the internet has been around?
Ever heard of this stuff called 'paper', and the concept of
'printing'?

I'm speaking of the > line prefix. And perhaps it's time you learn
that < is a transitive relationship.
 
F

Flash Gordon

Phil said:
If his issue was the lack of an atomic 'xor' primitive, then his
complaint should have been "because there doesn't exist an atomic
'xor' primitive", not "because I couldn't write a sensible 'xor'
function".

Indeed. There are also useful operators missing from C, for example the
logical xor operator. This is a serious comment, it is not required for
supposed short-circuit evaluation but to treat all non-zero values as
true. The following won't act as a logical exclusive or, for example:
strcmp(a,b) ^ strcmp(a,c)
There are plenty of functions in C which do not guarantee to return 1
for true. Plenty in the standard library, plenty in third party libraries.
 
B

Ben Bacarisse

Phil Carmody said:
If his issue was the lack of an atomic 'xor' primitive, then his
complaint should have been "because there doesn't exist an atomic
'xor' primitive", not "because I couldn't write a sensible 'xor'
function".

He did, of course, make exactly that claim in the preceding sentence.
If he had left it at that, do doubt someone would have piped up an
claimed that it does not matter that XOR is missing because you can
write an xor function. He needed to make both half of the argument --
that it is not there, and that it can't be sensibly written.
 
K

Keith Thompson

Phil Carmody said:
I'm not a python programmer, '"""' has nothing to do with python,
it's just an arbitrary string which won't by default be interpreted
as text, but as markup.

Ok. Python happens to use the same syntax for multi-line string
literals; I assumed that was the inspiration. Not a big deal.
Was the meaning of it unclear to you? Did
you not realise it was a block quote?

No, and no, respectively. (The meaning was not unclear, and I did
realize it was a block quote.)
Use of a line prefix rather than a block prefix would have required
on my part the insertion of characters to every line, and the possible
re-wrapping of text such that less-capable clients when replying do
not leave partial lines without the line prefix.

Yes, I do that all the time. I happen to use an editor that makes
that kind of thing fairly easy, but it should be possible in any
decent editor, with less effort than manually inserting a prefix on
each quoted line.
Preserving my markup would have required 1 less line deletion at
each end by the quoter.

If you were to have responded to my earlier post - would you
have preserved the '"""'? If so, why, and if not, why not?

Yes, I probably would have preserved it, for the obvious reasons. If
I wanted to re-quote only part of it, I suppose I would have inserted
a [...] and retained the opening and closing """ markers.

So yes, anyone quoting your article should be careful to indicate
quotation levels correctly. My suggestion is simply that you should
invest some effort to make that easier. The Usenet block quoting
convention is a "> " prefix on each line, and the vast majority of us
have newsreaders that handle that convention automatically. By using
a different convention, you impose extra effort on people reading your
articles.
 
N

Nate Eldredge

Flash Gordon said:
Indeed. There are also useful operators missing from C, for example
the logical xor operator. This is a serious comment, it is not
required for supposed short-circuit evaluation but to treat all
non-zero values as true. The following won't act as a logical
exclusive or, for example:
strcmp(a,b) ^ strcmp(a,c)
There are plenty of functions in C which do not guarantee to return 1
for true. Plenty in the standard library, plenty in third party
libraries.

But logical xor is a lot easier to write in terms of existing operators.

#define LOGICAL_XOR(a,b) (!!(a) ^ !!(b))
or
#define LOGICAL_XOR(a,b) (!!(a) != !!(b))

What's more, it's pretty easy for a compiler to optimize this. By
contrast, I seriously doubt that a compiler will optimize the
written-out xor function (using modular arithmetic and loops) in terms
of an xor instruction.
 
I

Ike Naar

But logical xor is a lot easier to write in terms of existing operators.

#define LOGICAL_XOR(a,b) (!!(a) ^ !!(b))
or
#define LOGICAL_XOR(a,b) (!!(a) != !!(b))

You can leave out a couple of exclamation marks:
#define LOGICAL_XOR(a,b) (!(a) != !(b))
 
P

Phil Carmody

I didn't write this.

I know. And if I'd have used my previously chosen quoting technique
rather than the one you recommended, that would have been clear.
Please keep up.
I didn't write this.

I know that too. And again, if I'd have used my previously chosen
quoting technique rather than the one you recommended, that would
have been clear. Please keep up, you appear a little slow.
You don't need to feel sorry for me.

But you still need to hone your usenet quoting skills.

Your inability to see what has just happened in the last 3
posts is astonishing.

Or the right problem: if your news reader doesn't implement ancestral
usenet conventions, then you should change your news reader.

You still don't understand the issue at hand, do you?
True. The usenet existed before the Internet.

Someone ought to tell Vint Cerf and the rest of the sentient world
that they're all wrong and only you are right.

On the other hand, maybe it's just you who's horrifically incorrect.
You're not confusing the world-wide web and the internet are you?
That a real newbie error.

Phil
 
P

Pascal J. Bourguignon

Phil Carmody said:
I know. And if I'd have used my previously chosen quoting technique
rather than the one you recommended, that would have been clear.
Please keep up.


I know that too. And again, if I'd have used my previously chosen
quoting technique rather than the one you recommended, that would
have been clear. Please keep up, you appear a little slow.


Your inability to see what has just happened in the last 3
posts is astonishing.



You still don't understand the issue at hand, do you?


Someone ought to tell Vint Cerf and the rest of the sentient world
that they're all wrong and only you are right.

On the other hand, maybe it's just you who's horrifically incorrect.
You're not confusing the world-wide web and the internet are you?
That a real newbie error.

Have a look at wikipedia articles about the Internet:

The first TCP/IP-based wide-area network was operational by
January 1, 1983 when all hosts on the ARPANET were switched over
from the older NCP protocols.


and Usenet:

Newsgroup experiments first occurred in 1979. Tom Truscott and Jim
Ellis of Duke University came up with the idea as a replacement for a
local announcement program, and established a link with nearby
University of North Carolina using Bourne shell scripts written by
Steve Bellovin. The public release of news was in the form of
conventional compiled software, written by Steve Daniel and Truscott.

UUCP networks spread quickly due to the lower costs involved, and the
ability to use existing leased lines, X.25 links or even ARPANET
connections. By 1983 the number of UUCP hosts had grown to 550, [...]


Otherwise, concerning newbie errors, I was reading some Usenet
newgroups thru bitnet mail-list gateways when I was at the university
in 1984. And I had an IP connection to the Internet before Tim
Berners-Lee had a NeXT computer.
 
P

Phil Carmody

Ben Bacarisse said:
He did, of course, make exactly that claim in the preceding sentence.
If he had left it at that, do doubt someone would have piped up an
claimed that it does not matter that XOR is missing because you can
write an xor function. He needed to make both half of the argument --
that it is not there, and that it can't be sensibly written.

I don't see what's not sensible about synthesising bit-oriented
operations using bitwise loops in a language which doesn't support
such things natively.

There's no k-ary addition operation in C, unlike LISP, say.
Is synthesising such an operation by a iterating over an array
which you have previously filled in with all the appropriate
values any more "sensible" than iterating over bits in Pascal?

Ditto bignums.

The problem is that "sensible" is in the eye of the beholder.
It's clear to me that he didn't consider needing a function to
perform the task to be intrinsically non-sensible, otherwise he
would, or should, have ended his argument with a conclusion
immediately after "In particular, there are no bit-manipulation
operators (AND, OR, XOR, etc.)".

Phil
 
C

CBFalconer

Harald said:
You do know that there is no keyword 'mod' in C, right? You need
to spell the operator properly, or you need to add a macro 'mod'
to make your code work. You said to add appropriate defines and
#includes, and I don't see anything that might need to be defined
by the user as a macro, so if not mod, what were you talking about?

Yes, sorry. I see it now. I just copied from the previous
message, without paying strict attention.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top