Afficher un message
Vieux 29/01/2008, 06h56   #2
Walter Roberson
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: What happens to this memory

In article <8d225f92-babf-4eac-b233-d8d8a5d18a6a@s12g2000prg.googlegroups.com>,
Joakim Hove <joakim.hove@gmail.com> wrote:

>I am considering to write a function like this:


> enum shape_enum {circle , rectangle};


> const char * shape_name(enum shape_enum shape_id) {
> if (shape_id == circle)
> return "Circle";
> else if (shape_id == reactangle)
> return "Rectangle";
> end


> printf("The name of the shape is: %s \n",shape_name(shape_id));


>But I am wondering what happens to the memory allocated(??) for the
>strings "Rectangle" and "Circle". Can I exhaust my available memory by
>calling shape_name() sufficiently many times?


That's a good question to be asking, and the answer is NO, you
cannot exhaust memory that way. Constant string literals such as
"Circle" are guaranteed to exist for the life of the program

(I would need to check the exact wording to figure out
if they still exist while processing a routine registed
via atexit() )
--
This is a Usenet signature block. Please do not quote it when replying
to one of my postings.
http://en.wikipedia.org/wiki/Signature_block
  Réponse avec citation
 
Page generated in 0,05125 seconds with 9 queries