Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > pointer concept

Reply
Thread Tools

pointer concept

 
 
karthikbalaguru
Guest
Posts: n/a
 
      10-30-2007
On Oct 29, 1:38 pm, Ben Bacarisse <(E-Mail Removed)> wrote:
> gsingh <(E-Mail Removed)> writes:
> > char *p="str";

>
> > How much memory will be allocated for this.

>
> Such questions don't have simple answers. If the compiler can detect
> that 'p' is not required, it may not actually allocate any memory at
> all. It is even possible (depending on the context) that the compiler
> might eliminate the string literal!


Interesting way of thinking

Karthik Balaguru

 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      10-30-2007
Keith Thompson said:

> Old Wolf <(E-Mail Removed)> writes:
>> On Oct 30, 7:29 am, Keith Thompson <(E-Mail Removed)> wrote:
>>> (E-Mail Removed) (Richard Tobin) writes:

<snip>
>>>
>>> > How could you possibly tell? (So long as sizeof returns the expected
>>> > answer.)
>>>
>>> By examining the generated code.

>>
>> There might not be any generated code, depending on
>> which optimisations the compiler is able to make.

>
> If there's no generated code, then the amount of allocated space is
> zero (though it's still the same in the abstract machine).


C can be interpreted. Interpreters do not (necessarily) generate code in
the sense of an object file that you can examine. So do C interpreters run
their programs in 0 memory?

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      10-30-2007
CBFalconer said:

> Richard Heathfield wrote:
>> gsingh said:
>>
>>> char *p="str";
>>>
>>> How much memory will be allocated for this.

>>
>> At least four bytes for the string literal, and sizeof p bytes
>> for the pointer.

>
> The literal may not be needed. For example:
>
> char *o = "First str";
> char *p = "str";
>
> in which *p may well point to the "str" portion of "First str".


That's actually a good example of the string literal needing more than four
bytes.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -http://www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Pointer concept in Ruby ? IƱaki Baz Castillo Ruby 11 04-25-2008 09:09 AM
Sonet Pointer justification Concept ekavirsrikanth@gmail.com VHDL 4 03-14-2008 06:51 AM
Problem in the aggregation concept.(during deletion of the pointer of other class). Aff@n C++ 1 10-16-2006 05:08 AM
pointer and variable scope concept a C Programming 2 07-10-2006 08:14 AM
RCR 304: reference/pointer concept Eric Mahurin Ruby 2 05-09-2005 03:27 PM



Advertisments