Null casting for structure pointer in C?

Is there any advantage of casting NULL to a structure pointer in C?

For instance:

typedef struct List
{
....
} List;

List *listPtr = ((List *) NULL) ;

An example from a PostgreSQL source:

#define NIL                     ((List *) NULL)

http://doxygen.postgresql.org/pg__list_8h_source.html

+5
source share
3 answers

In the assignment example, explicit listing does not make sense. However, it seems that you are really wondering about a macro #define NIL ((List *) NULL)whose usability is beyond the scope of the destination.

, , - , . NULL 0 0L ((void *) 0) - , , - . , .

, ( undefined)

void foo();

int main() {
  foo(NULL);
}

void foo(List *p) {
  /* whatever */
}

foo(NIL);

.

+8

- NULL C

. :

List *listPtr = NULL;

, (, ), NULL.

+4

null null, null, , , , .

+4

All Articles