C warning Missing sentinel in function call C warning Missing sentinel in function call c c

C warning Missing sentinel in function call


It looks like you may not have terminated an array declaration with NULL. Without the null you may have some memory weirdness as the runtime won't know where the array ends and the next bit of memory starts.


I just came across the same issue. The code which was causing it for me was...

execl("/bin/bash", "/bin/bash", fname, '\0');

but it should be...

execl("/bin/bash", "/bin/bash", fname, (char *)0);

The problem with the first version is that the list of parameters is meant to end with a null pointer. But '\0' is not a null pointer, it's a null character. So the value (0) is correct, it's just the type is wrong.

The (char *)0 is also zero, but cast as a char pointer, which is a null pointer (ie it points to address 0). This is needed so the system can tell where the parameter list ends so that it doesn't keep scanning for parameters after the last one. Doing that would get it invalid pointers which could point to any memory - which likely would cause a segmentation fault.

That (char *)0 is called the sentinel, and it's what was missing from the first example.

Finally note that NULL is defined as (void *)0, so

execl("/bin/bash", "/bin/bash", fname, NULL);

Works just as well, and is a little more convenient. (Thanks to @mah for that).


In Xcode if you are coding in objective-c and you are using some methods which take variable parameter list, you need to add nil object at the end of the list.

For example:

NSArray *names = [NSArray arrayWithObjects: @"Name1", @"Name2"]; //will result in the warning mentioned above

However, NSArray *names = [NSArray arrayWithObjects: @"Name1", @"Name2", nil]; //Correct

Hope this will help!