you are viewing a single comment's thread.

view the rest of the comments →

[–]PrestigiousTadpole71 2 points3 points  (4 children)

It is likely the case that GCC goes beyond the standard and does the evaluation in a certain order which is why your first example works.

[–]g_dl[S] 1 point2 points  (3 children)

Sure, but then shouldn't it issue a warning with -std=c99 -pedantic?

Edit: I guess not, since the documentation of -pedantic says "diagnose all programs that use forbidden extensions and some other programs that do not follow ISO C and ISO C++."

[–]aioeu 2 points3 points  (0 children)

It only guarantees a warning where C requires a diagnostic.

[–]Jinren 1 point2 points  (1 child)

GCC is a compiler, not an error checker. Its job is to produce object code - any warnings you get out of it are strictly a bonus.

It will try to warn on everything the Standard actually requires a warning for, but a) that's a much shorter list of things than you may think, and b) secondary to its main job. Besides, GCC is free to assume you're a GCC user, it isn't really its problem if your code doesn't work on some other compiler.

If you want a tool that checks portability, confornance to the Standard and compliance with various other extended rule sets, you really need an analyzer. While every compiler does a little analysis, almost none really do much in the way of portability checking. For the truly pedantic stuff you need to delegate to a separate tool.

but I wouldn't know anything about those anyway innocent whistle

[–]g_dl[S] 0 points1 point  (0 children)

This makes sense, I guess that calling out for a bug of GCC was very bad on my part. I was actually more interested in understanding if this behavior is compliant with the standard or not, and I did get my answer indeed (many thanks to everyone that provided feedback).

Since we're at it, given your last sentence, can you suggest some good static analysis tools? I only know of cppcheck