Some Questions

F

fctk

pete ha scritto:
I think it helps to consider that
int i = 0;
is shorthand for
int i = {0};
and that {0} is not an expression.

Those are declarations, not statements.
And those are initializations, not assignments.

so in:

int i = ((564 * 793) / 5 );

((564 * 793) / 5 ) is not an expression?
 
K

Keith Thompson

fctk said:
pete ha scritto:

That's a consistent way of looking at it, but it's not how I'd put it.

I'd say that {0} is longhand for 0, not that 0 is shorthand for {0}.
so in:

int i = ((564 * 793) / 5 );

((564 * 793) / 5 ) is not an expression?

Yes, it is.

In a declaration such as

int i = blah;

blah is an "initializer". An initializer can be, among other things,
an assignment-expression (i.e., an expression other than a
comma-expression) or an initalizer-list enclosed in '{' and '}'
characters.

So given
int i = ((564 * 793) / 5 );
((564 * 793) / 5 ) is an expression. Given
int i = { ((564 * 793) / 5 ) };
((564 * 793) / 5 ), but { ((564 * 793) / 5 ) } is not.
 
C

Chris Torek

OED indicates:

Semantic: B. n. pl.
1.a = SEMASIOLOGY. Als, (the study or analysis of) the relationships
between linguistic symbols and their meanings. Const. as sing. and pl.
Now the usual word in this sense.

The equal sign is a "linguistic symbol". The -meaning- of that linguistic
symbol in context is semantics, not syntax. Syntax tells you that the
equal sign must occur there, but not what it denotes.

This discussion is especially confusing (or potentially quite
confusing) because there are two English words, "syntax" and
"semantics", and two C-Standard-ese words, "syntax" and "semantics",
with somewhat different definitions.

The only way to talk about all this without getting confused is
to re-label all four words. Since color is not available and
case is confusing, I think the best way is to make up entirely
new words:

mag: "C syntax", i.e., the grammar in the C standard;
pag: "C semantics", i.e., the stuff that goes in paragraphs
under a section labeled "semantics";
vag: "English syntax" (we mostly are not using this one here);
zag: "English semantics", as per the definition quoted above.

The "=" in an initializer such as "int i = 0" is definitely,
certainly, nothing but mag and not pag. It is, however, a
matter of zag (and not vag), as Walter Roberson points out,
when we start talking about whether it is "only" a symbol
(but, as he also noted, it is definitely not an assignment
operator as defined by mag and described under pag), since
"assignment operators" (as per mag) include things like +=
and -=.

We can see that it is a matter of mag when we look at Historical
C -- the stuff that came before even K&R C -- where initializers
were written without the "=" sign:

int debug 0;
int interactive 1;

main(argc, argv)
char **argv;
{
int i 1;
char *s;
int read_stdin 0;

while (i < argc) {
s = argv;
/* -d = debug */
/* -q = quiet = not-interactive */
/* - = read stdin */
if (*s == '-') {
if (s[1] == 'd')
debug++;
else if (s[1] == 'q')
interactive = 0;
else if (s[1] == '\0')
read_stdin = 1;
else
usage();
}
...
i++;
}
...
}

This dialect of C also had the assignment operators spelled
the other way around; instead of "debug++" we might write:

debug =+ 1;

The syntax was changed because it was inconsistent (or even "ugly"),
and expressions like "k=-5" were ambiguous to human readers, who
might see that as either "k = -5" (set k to -5) or "k =- 5" (decrement
k by 5).

(This version of C also had oddities like:

printf(2, "some debug message\n");

where the first argument, if not a string, was treated as a Unix
file descriptor. The two were distinguished purely by "magic":
strings were known to have addresses greater than 19. This trick
stopped working when the system was ported to split-I&D PDP-11s,
and the data segment began at 0 just like the code segment.)
 
R

Rod Pemberton

Chris Torek said:
We can see that it is a matter of mag when we look at Historical
C -- the stuff that came before even K&R C -- where initializers
were written without the "=" sign:

This dialect of C also had the assignment operators spelled
the other way around; instead of "debug++" we might write:

debug =+ 1;

The syntax was changed because it was inconsistent (or even "ugly"),
and expressions like "k=-5" were ambiguous to human readers, who
might see that as either "k = -5" (set k to -5) or "k =- 5" (decrement
k by 5).

Do you have more information on that? I thought I read somewhere that the
"reversed" operators of early C were changed because bison and lex grammars
had parsing/lexing problems.


Rod Pemberton
 
J

Joe Wright

Rod said:
Chris Torek said:
Do you have more information on that? I thought I read somewhere that the
"reversed" operators of early C were changed because bison and lex grammars
had parsing/lexing problems.


Rod Pemberton
In K&R 1 on page 212, A.17 Anachronisms: explains it like Chris does.
There is no mention of bison or lex.
 
M

Micah Cowan

Joe Wright said:
Rod said:
In K&R 1 on page 212, A.17 Anachronisms: explains it like Chris
does. There is no mention of bison or lex.

Also, I don't see why it should be a particular problem for bison or
lex, particularly since lex tends to match the longest possible
sequence, IIRC.
 
R

Rod Pemberton

Micah Cowan said:
Joe Wright said:
Rod said:
Also, I don't see why it should be a particular problem for bison or
lex, particularly since lex tends to match the longest possible
sequence, IIRC.

Well, I can't find it at the moment. I did find these:

Wikipedia
http://en.wikipedia.org/wiki/C_programming_language
"The =+ operator was changed to += to remove the semantic ambiguity created
by the construct i=+10, which could be interpreted as either i =+ 10 or i =
+10. "


"The Development of the C Language" by Dennis M. Ritchie, Bell Labs/Lucent
Technologies, Murray Hill, NJ 07974 USA

On page 5,
"More History
After the TMG version of B was working, Thompson rewrote B in itself (a
bootstrapping
step). During development, he continually struggled against memory
limitations: each language
addition inflated the compiler so it could barely fit, but each rewrite
taking advantage of the feature
reduced its size. For example, B introduced generalized assignment
operators, using x=+y
to add y to x. The notation came from Algol 68 [Wijngaarden 75] via McIlroy,
who had incorporated
it into his version of TMG. (In B and early C, the operator was spelled =+
instead of += ;
this mistake, repaired in 1976, was induced by a seductively easy way of
handling the first form
in B's lexical analyzer.)"


From 7.14.1 of 1975's "C Reference Manual", Dennis M. Ritchie, Bell
Telephone Laboratories, Murray Hill, New Jersey 07974, I know the following
operators were reverse from what they are today:

7.14.2 lvalue =+ expression
7.14.3 lvalue =- expression
7.14.4 lvalue =* expression
7.14.5 lvalue =/ expression
7.14.6 lvalue =% expression
7.14.7 lvalue =>> expression
7.14.8 lvalue =<< expression
7.14.9 lvalue =& expression
7.14.10 lvalue =^ expression
7.14.11 lvalue = | expression


Oh well, it's not important.


Rod Pemberton
 

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
474,176
Messages
2,570,950
Members
47,503
Latest member
supremedee

Latest Threads

Top