Re: Help in c pointers
- From: Jordan Abel <random832@xxxxxxxxx>
- Date: 28 Feb 2006 19:29:10 GMT
On 2006-02-28, Pedro Graca <hexkid@xxxxxxxxxxx> wrote:
Jordan Abel wrote:
On 2006-02-28, Kenneth Brody <kenbrody@xxxxxxxxxxx> wrote:
"manochavishal@xxxxxxxxx" wrote:
int *p;
*p = 4;
char * msg;
*msg = 'c';
printf("msg is %s",msg);
Neither pointer has been initialized, and both assignments invoke UB.
Incidentally, there's a third instance of undefined behavior here -
anyone know what it is?
a) `msg' isn't (*) a c-string (a sequence of chars ending in NUL) so
passing it to printf invokes UB.
Not quite - msg isn't a valid pointer at all, so the act itself of
passing it to printf invokes UB. It would equally invoke UB if it were a
void * and being passed to a printf %p format.
The value of msg is indeterminate since it is never initialized. Reading
an indeterminate value results in undefined behavior [since it may be a
trap representation]
.
- References:
- Help in c pointers
- From: manochavishal@xxxxxxxxx
- Re: Help in c pointers
- From: Kenneth Brody
- Re: Help in c pointers
- From: Jordan Abel
- Re: Help in c pointers
- From: Pedro Graca
- Help in c pointers
- Prev by Date: Re: a question of style
- Next by Date: Re: Way for computing random primes in standard C.
- Previous by thread: Re: Help in c pointers
- Next by thread: Re: Help in c pointers
- Index(es):
Relevant Pages
|