A bug?

2008-12-16 Thread Michel Van den Bergh
Hi, The following program segfaults when compiled with gcc but runs fine when compiled with g++ or icc (the intel C compiler) #include struct Hello { char world[20]; }; struct Hello s(){ struct Hello r; r.world[0]='H'; r.world[1]='\0'; return r; } int main(){

Re: A bug?

2008-12-16 Thread Michel Van den Bergh
That's strange. When I try to compile this with gcc 4.3.2 on Ubuntu 8.10 (Intel core2 duo) I get stest.c: In function ‘main’: stest.c:13: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char[20]’ The resulting binary does not segfault but prints garbage (probably uniniti

Re: no conversion from char[] to char* on function calls under circumstances [was: A bug?]

2008-12-16 Thread Michel Van den Bergh
Ok thanks for the clear explanation! Not being able to threat char[] as a string is rather shocking to me though. Regards, Michel

Re: A bug

2008-12-16 Thread Michel Van den Bergh
The C standard says no such thing; only integer promotions are performed. (See 6.5.2.2 of the C99 final draft.) Ok one more question. Why does this not give a warning then (and runs fine)? #include struct Hello { char world[20]; }; struct Hello s(){ struct Hello r; r.wor

Re: no conversion from char[] to char* on function calls under circumstances [was: A bug?]

2008-12-16 Thread Michel Van den Bergh
Andrew Haley wrote: Andrew Thomas Pinski wrote: C++98 is not C99 :) there is no rvalue to lvalue conversion for rvalue arrays in C++98. Also this code is still undefined C99 but will most likely become valid C1x. Ah, it's an rvalue array. Good point. Ok now I understand. I assume t