|
||||||||||||||||||
Add Forum to Favorites | Send Topic To a Friend | View Forum FAQ | Track this topic |
Last Thread Next Thread ![]() |
| String Usage and Architecture |
|
![]() Anonymous Poster |
||||
|
||||
| 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. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| Global variables are in the data section, not on the heap. |
||||
|
||||
![]() Anonymous Poster |
||||
|
||||
| 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. |
||||
|
||||
![]() Wc-duck Member since: 12/12/2006 From: Stockholm, Sweden |
||||
|
|
||||
| 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. |
||||
|
||||
![]() grekster Member since: 4/23/2004 From: Whitley Bay, United Kingdom |
||||
|
|
||||
Quote: Actually im fairly sure that myarray[2] and *(myarray+2) are exactly the same. |
||||
|
||||
![]() Evil Steve Moderator Member since: 6/30/2003 From: Glasgow, United Kingdom |
||||
|
|
||||
Quote: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. |
||||
|
||||
![]() Wc-duck Member since: 12/12/2006 From: Stockholm, Sweden |
||||
|
|
||||
| ahh... missed the mulitplication with the index. My bad. |
||||
|
||||
![]() Wc-duck Member since: 12/12/2006 From: Stockholm, Sweden |
||||
|
|
||||
| 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). |
||||
|
||||
![]() Wc-duck Member since: 12/12/2006 From: Stockholm, Sweden |
||||
|
|
||||
| ok... I was wrong. Tested and verified now. |
||||
|
||||
All times are ET (US)![]() |
Last Thread Next Thread ![]() |
|