Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Declaring variables

Name: Anonymous 2010-05-01 17:18

Should one declare variables (in C) at the begining of a function? I allways declared them before the first use, now i start to question if this is right.
What is the right thing to do /prog/?

Name: Anonymous 2010-05-01 17:23

If the code you're writing is strict C89, then you should do it at the beginning of the code block. If it's something newer that allows declaring it in random places, then do whatever you wish. I tend to declare it at the beginning, since I like compatibility with a lot of compilers (for example, MS' Optimizing C compiler (MSVC's) tends to be C89-only in its C mode. Of course I could just use C++ mode, but I'd rather not).

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List