From: Spiro Trikaliotis (ml-cbmhackers_at_trikaliotis.net)
Date: 2005-04-01 14:14:56
Hello Gabor, * On Fri, Apr 01, 2005 at 01:36:01PM +0200 Gabor Lenart wrote: > Hmmm, anyway I would NEVER use an uninitialized variable whatever even > not-exactly-compatible standards say between multiple > architectures/compilers :) Also some compilers dump warning message if > you try this. And I bet it's a good advice to avoid this madness also > ... No, it is not madness. In fact, I have not found a compiler which does not behave this way for very long. I'm not sure if I ever have seen a compiler which did not behave this way. Let's look at this: [abc.c] int global_init = 1; int global_uninit; void func(void) { int local_init = 1; int local_uninit; } In this case, only local_uninit has an arbitrary value, and most compiler will (most hopefully) warn if you use it before you initialize it. OTOH, global_uninit has to be set to 0 (specified by the standard), thus, you can use it whenever you like. Personally, I find it a good habit to initialize it to 0 anyway, but this is not necessary. BTW: It would be very hard for a compiler to warn about using global_uninit without initializing it, because the compiler would have to analyze the complete program in the general case. Regards, Spiro. -- Spiro R. Trikaliotis http://www.trikaliotis.net/ Message was sent through the cbm-hackers mailing list
Archive generated by hypermail pre-2.1.8.