Path: utzoo!attcan!uunet!lll-winken!lll-tis!ames!husc6!rutgers!gatech!gt-eedsp!baud From: baud@gt-eedsp.UUCP (Kurt Baudendistel) Newsgroups: comp.lang.c++ Subject: operator precedence question Keywords: c++, precedence Message-ID: <347@gt-eedsp.UUCP> Date: 19 Jul 88 15:32:10 GMT Distribution: na Organization: School of Electrical Engineering, Ga. Tech, Atlanta, GA 30332 Lines: 33 in the following code fragment, foo(char *s, char *t) { char *r = "hello, there"; ... for ( int i=0, t=s; i < 10; i++ ) *t++ = *r++; ... your initial reaction is that everything is okay, and that this will copy the first 10 characters of "hello, there" into the buffer pointed to by s. however, this is not the case (at least with my compiler -- gnu g++). what the compiler thinks is that the portion of the for statement "int i=0, t=s;" is a statement which says "declare 2 integers i and t, and initialize them to the values '0' and 's', respectively." this also creates an error to the effect that s is the wrong type (a pointer to char rather than an int, but that is not relevant here). it seems strange to me that when i used then `poor' variable declaration technique of c (define all variables like `i' at the beginning of the module) that the comma operator was a valuable part of the for statement syntax, but that conversion to `proper' c++ variable declaration technique (at the point of usage) invalidates the format of the for statement. why is this? -- Kurt Baudendistel [GRA McClellan] Georgia Tech, School of Electrical Engineering, Atlanta, GA 30332 USENET: ...!{allegra,hplabs,ihnp4,ulysses}!gatech!gt-eedsp!$me INTERNET: $me@gteedsp.gatech.edu