Re: Problem using string pointer
From: David Webber (dave_at_musical.demon.co.uk)
Date: 03/10/04
- Next message: lallous: "Re: possible consequences of not using MT"
- Previous message: kailasam: "Problem using string pointer"
- In reply to: kailasam: "Problem using string pointer"
- Next in thread: lallous: "Re: Problem using string pointer"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 10 Mar 2004 08:15:11 -0000
"kailasam" <kailasam.pk@in.bosch.com> wrote in message
news:c2mhir$ksp$1@ns1.fe.internet.bosch.com...
> METHOD 1 :
> char *str = " ADGFR";
> *str = 'c';
One learns not to do this. The actual data " ADGFR" is just a
constant stored somewhere or other and str is a pointer (put on the
stack) which points to it - wherever it is. I am not sure that the
C or C++ languge specification says where " ADGFR" should be stored,
or what you should be allowed to do with the data buffer. If you
really must use this then
const char *str = " ADGFR";
is much better.
> METHOD2:
> char str[] = " ADGFR";
> *str = 'c';
This is completely different! My understanding is that it allocates
7 bytes on the stack for str[] and copies " ADGFR" into it. The
data on the stack is your property and so you can manipulate str[]
as you would any old 7 bytes of stack.
Dave
-- David Webber Author MOZART the music processor for Windows - http://www.mozart.co.uk For discussion/support see http://www.mozart.co.uk/mzusers/mailinglist.htm
- Next message: lallous: "Re: possible consequences of not using MT"
- Previous message: kailasam: "Problem using string pointer"
- In reply to: kailasam: "Problem using string pointer"
- Next in thread: lallous: "Re: Problem using string pointer"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|