Re: Help in c pointers



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.

b) printf doesn't end with a newline nor is followed by a
fflush(stdout); invoking implementation defined behaviour (???)


(*) probably it is -- there probably is a nul between msg and msg+<some
large integer value>.

--
If you're posting through Google read <http://cfaj.freeshell.org/google>
.



Relevant Pages

  • Re: Help in c pointers
    ... points to it says seg fault but for the char pointer it works fine. ... Neither p nor msg points anywhere. ... them results in undefined behavior. ...
    (comp.lang.c)
  • race condition?
    ... logit(LOG_DEBUG, "put debug msg here"); ... logfile then creates a FIFO and opens it for reading. ... logit(int priority, const char *msg) ...
    (comp.unix.programmer)
  • Re: How connect PC Embedded to MDB (Vending Machine)
    ... char by using the mark/space parity control. ... can filter on the 9th bit set (MDB address mode). ... msg within 5mS. ... device response time at best. ...
    (comp.arch.embedded)
  • Re: Highly efficient string reversal code
    ... a char cannot have unused bits. ... Not in C99. ... In C99, if you read a trap representation, the ... code invokes undefined behavior. ...
    (comp.lang.c)
  • Re: How connect PC Embedded to MDB (Vending Machine)
    ... char by using the mark/space parity control. ... msg within 5mS. ... device response time at best. ... be 72mS + device response time. ...
    (comp.arch.embedded)