Re: whether this is valid
From: Joona I Palaste (palaste_at_cc.helsinki.fi)
Date: 06/26/04
- Next message: Christian Bau: "Re: whether this is valid"
- Previous message: CBFalconer: "Re: keyword extern"
- In reply to: madhur: "whether this is valid"
- Next in thread: Christian Bau: "Re: whether this is valid"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 26 Jun 2004 21:01:16 GMT
madhur <madhur@sdf.com> scribbled the following:
> Hello
> char *a="str";
> strcpy(a,"abc");
> I have learnt that since "a" is a string literal, it might be allocated on
> read only memory on some implementations.
> Is it correct to modify a string literal using this way.
Not, it's not correct. It might work or "work" on some implementations
but that's due to either special allowances or sheer dumb luck. The
above code causes undefined behaviour and thus should never be relied
on.
-- /-- Joona Palaste (palaste@cc.helsinki.fi) ------------- Finland --------\ \-- http://www.helsinki.fi/~palaste --------------------- rules! --------/ "As we all know, the hardware for the PC is great, but the software sucks." - Petro Tyschtschenko
- Next message: Christian Bau: "Re: whether this is valid"
- Previous message: CBFalconer: "Re: keyword extern"
- In reply to: madhur: "whether this is valid"
- Next in thread: Christian Bau: "Re: whether this is valid"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|