variable initialisation

Sep 1, 2006 at 9:34am

variable initialisation

What is the difference between initializing the variables at the
beginning of the code, and initializing the variables in the main()
function ?

best

f.e

f.e chanfrault | aka | personal computer music
> >>>>>> http://www.personal-computer-music.com
> >>>>>> |sublime music for a desperate people|

#27421
Sep 1, 2006 at 6:41pm

On 1-Sep-2006, at 11:34, f.e wrote:
> What is the difference between initializing the variables at the
> beginning of the code, and initializing the variables in the main()
> function ?

In the first case the compiler generates whatever code is necessary
to initialize the variable before the first explicit line of main()
is called.

In general I prefer to initialize variables before main(), to avoid
doing something stupid like using the variable two lines before the
first assignment (modern compilers will warn about this, but they
used not to!)

Note that you can’t use a function call like gensym() for
initialization. Still, it’s a good idea to explicitly initialize to
NULL in the variable definition and then assign the gensym() result
early in your code.

Also, C (unlike Pascal) doesn’t force you to put the intialization at
the top of the file. Extern and static declarations/definitions can
occur anywhere. But don’t do that;-

————– http://www.bek.no/~pcastine/Litter/ ————-
Peter Castine +–> Litter Power & Litter Bundle for Jitter
Universal Binaries on the way
iCE: Sequencing, Recording &
Interface Building for |home | chez nous|
Max/MSP Extremely cool |bei uns | i nostri|
http://www.dspaudio.com/ http://www.castine.de

#82970

You must be logged in to reply to this topic.