Home » Community » Forums » » String Usage and Architecture
  Intel sponsors gamedev.net search:   
[Control Panel] [Register] [Bookmarks] [Who's Online] [Active Topics] [Stats] [FAQ] [Search]

Add Forum to Favorites |  Send Topic To a Friend | View Forum FAQ | Track this topic


 Last Thread Next Thread 
 String Usage and Architecture
Post Reply 
The authors writes that global variables are allocated on the heap. This comes as a surprise to me, so I wonder if my understanding is incorrect, or whether the author is incorrect on this point.

I had previously thought that global variables were allocated in the "static area", an are that is neither part of the heap, nor part of the stack.

Perhaps there are some architectures (maybe on gaming machines?) where global variables are on the heap, but I'd be surprised if this was true in general. I'll look into it further, and I'd invite the author (and readers of this article) to do the same.

 User Rating: 1015    Report this Post to a Moderator | Link

Global variables are in the data section, not on the heap.

 User Rating: 1015    Report this Post to a Moderator | Link

Some of the stuff the author does in the article could be potentially dangerous, with things like sscanf etc. You tend to avoid that since you have no control over out of bounds stuff.

 User Rating: 1015    Report this Post to a Moderator | Link

Read this right now and needed to point out an error:

The author says "myarray[2] is really just shorthand for *(myarray+2)". That is not true myarray[2] is the same as *(myarray+sizeof(myarray_element_type)) and that is acctually a huge difference.

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Wc-duck
Read this right now and needed to point out an error:

The author says "myarray[2] is really just shorthand for *(myarray+2)". That is not true myarray[2] is the same as *(myarray+sizeof(myarray_element_type)) and that is acctually a huge difference.


Actually im fairly sure that myarray[2] and *(myarray+2) are exactly the same.


 User Rating: 1353   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Quote:
Original post by Wc-duck
The author says "myarray[2] is really just shorthand for *(myarray+2)". That is not true myarray[2] is the same as *(myarray+sizeof(myarray_element_type)) and that is acctually a huge difference.
No it's not. The element size is implicit in both cases. The only time the element size matters is if you're dealing with raw bytes, such as for memcpy().

myarray[2] is the same as *(myarray+2). Try it with an array of ints and see.

 User Rating: 2014   |  Rate This User  Send Private MessageView ProfileView JournalView GD Showcase Entries Report this Post to a Moderator | Link

ahh... missed the mulitplication with the index. My bad.

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

Are you sure that the size is implied? I have done the exact same thing some time ago and i sertainly did not work. But I'll try it again when I get home (at "work" now).

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

ok... I was wrong. Tested and verified now.

 User Rating: 1019   |  Rate This User  Send Private MessageView Profile Report this Post to a Moderator | Link

All times are ET (US)

Post Reply
 Last Thread Next Thread 
Forum Rules:
You may not post new threads
You may post replies
You may not edit your posts
You may not use HTML in your posts
Jump To:
Administrative Options: