Time4Tea
Time4Tea

Reputation: 123

What does this C struct assignment mean?

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

Answers (3)

0___________
0___________

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

Jean-François Fabre
Jean-François Fabre

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

madago
madago

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

Related Questions