Reputation: 123
I'm trying to read through some C source code and I've come across a structure assignment that I don't understand:
static struct sym_table *sym_array = (struct sym_table *) 0;
I understand that the left-hand-side is trying to initialize a pointer to a structure of type 'sym_table' (which is defined elsewhere); however, I am struggling to understand the right-hand-side. It's probably fairly simple, but I can't find any similar examples of this sort of assignment in any of the online C tutorials that I've seen.
If anyone can shed some light on it, I would really appreciate it!
Upvotes: 1
Views: 103
Reputation: 67546
this the Stroustrup way. He hates macros. So he always uses 0
in his code or eventually when keyword nullptr
was introduced the nullptr
. I think it is from the C++ code or from the program written by someone who usually uses C++.
Upvotes: 2
Reputation: 140196
static struct sym_table *sym_array = (struct sym_table *) 0;
is a slightly cumbersome way to set a pointer to NULL
, NULL
being defined in stdio.h
as ((void *)0)
. You'd be better off with:
static struct sym_table *sym_array = NULL;
Upvotes: 4
Reputation: 149
The right-hand-side is the equivalent of NULL pointer. But here , it is a NULL pointer of type (struct sym_table *)
Upvotes: 2