C
cc
In C, is derefencing a null pointer illegal?
In said:In C, is derefencing a null pointer illegal?
In C, is derefencing a null pointer illegal?
In C, is derefencing a null pointer illegal?
C is a typed language that supports pointers(*) to even the void type
and a function with variable arguments in various types and lengths.
I think C is not good for beginners without HW knowledge to mess around
with pointers and boundaries of arrays not checked in loops or even in
any access instances.
In C, is derefencing a null pointer illegal?
The behavior is "undefined" - any result is possible. On platforms
such as Windows or *nix, you'll most likely get a segfault.
It's definitely a logic error, since NULL represents a well-defined
"nowhere"; there shouldn't *be* anything there.
Of course there is something at adress zero :
on a home-made uP electronic board one can map
a RAM chip at address zero and read/write here.
C compilers prohibits the dereference
of zero pointer just to check for errors.
Richard Damon said:Undefined behavior may do something useful. On many machines the
memory pointed to by a null pointer is not in the user addressable
space, and a trap will occur on access. On others, you may not get a
trap, but it will access memory that has special purposes.
88888 dihedral said:I think C is not good for beginners without HW knowledge ...
Of course there is something at adress zero :
on a home-made uP electronic board one can map
a RAM chip at address zero and read/write here.
C compilers prohibits the dereference
of zero pointer just to check for errors.
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.