Re: server/fd.c: Prevent using uninitialized pointers
2009/6/30 Daniel Santos <javatroubadour(a)yahoo.com>:
Some pointers are getting used prior to initialization. It would appear that the current compilers are initializing them to zero or we've been lucky.
No, the C standard specifies that these are initialized to NULL, since they have static storage duration.
Henri Verbeet wrote:
2009/6/30 Daniel Santos <javatroubadour(a)yahoo.com>:
Some pointers are getting used prior to initialization. It would appear that the current compilers are initializing them to zero or we've been lucky.
No, the C standard specifies that these are initialized to NULL, since they have static storage duration.
We are assuming that the c compilers are following the standard. I was told a long time ago, 1994 to be exact, that if we want to insure that a variable has a certain value to initialize it to that value. This applies if we want a zero or a NULL. [code] int a = 0; char b = NULL; bool c = TRUE; [/code] Without this, we cannot assume anything. James McKenzie
James McKenzie wrote:
[code]
int a = 0; char b = NULL; bool c = TRUE;
[/code]
Without this, we cannot assume anything.
Static variables are different. They are always initialized to 0. In your example you show regular variables only. Their initial value is not defined. Vitaliy.
Vitaliy Margolen wrote:
James McKenzie wrote:
[code]
int a = 0; char b = NULL; bool c = TRUE;
[/code]
Without this, we cannot assume anything.
Static variables are different. They are always initialized to 0. In your example you show regular variables only. Their initial value is not defined.
Correct. I was making the assumption that the discussion was not about static variables. Static variables are always initialized: static int a; will be zero static char b; will be NULL static bool c; will be set to false (0) unless zero is defined as TRUE. However, if you want a particular result, it is always best to initialize the variables you are going to use. James McKenzie
On 07/04/2009 11:22 PM, James McKenzie wrote:
Vitaliy Margolen wrote:
James McKenzie wrote:
[code]
int a = 0; char b = NULL; bool c = TRUE;
[/code]
Without this, we cannot assume anything.
Static variables are different. They are always initialized to 0. In your example you show regular variables only. Their initial value is not defined.
Correct. I was making the assumption that the discussion was not about static variables. Static variables are always initialized:
static int a;
will be zero
static char b;
will be NULL
or, more precisely (pedantically) NUL or '\0' (which just happens to be the same as NULL [all bits set to 0] on most (all?) architectures IIRC) Frédéric
2009/7/4 Vitaliy Margolen <wine-devel(a)kievinfo.com>:
Static variables are different. They are always initialized to 0. In your Yes, although perhaps it should be noted that in this particular case the static storage duration is due to these being global variables, rather than the static keyword which just specifies internal linking here. (I.e., if they had external linking the pointers would still be initialized to NULL.)
participants (4)
-
Frédéric Delanoy -
Henri Verbeet -
James McKenzie -
Vitaliy Margolen