473,398 Members | 2,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Order of structure members in memory

Are the members of a struct guaranteed to have ascending memory
addresses?

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #1
5 1661
On Sun, 26 Sep 2004 19:15:05 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote in comp.lang.c:
Are the members of a struct guaranteed to have ascending memory
addresses?


Yes, always in C.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~a...FAQ-acllc.html
Nov 14 '05 #2
Christopher Benson-Manica <at***@nospam.cyberspace.org> writes:
Are the members of a struct guaranteed to have ascending memory
addresses?


Yes.
--
"A lesson for us all: Even in trivia there are traps."
--Eric Sosman
Nov 14 '05 #3
Jack Klein <ja*******@spamcop.net> spoke thus:
Yes, always in C.


Just for my edification, what is the chapter and verse? Thanks...

--
Christopher Benson-Manica | I *should* know what I'm talking about - if I
ataru(at)cyberspace.org | don't, I need to know. Flames welcome.
Nov 14 '05 #4
On Sun, 26 Sep 2004 20:07:47 +0000 (UTC), Christopher Benson-Manica
<at***@nospam.cyberspace.org> wrote:
Jack Klein <ja*******@spamcop.net> spoke thus:
Yes, always in C.


Just for my edification, what is the chapter and verse? Thanks...


In C99, it's 6.7.2.1, paragraph 13.

--
Eric Amick
Columbia, MD
Nov 14 '05 #5
Christopher Benson-Manica wrote:
Jack Klein <ja*******@spamcop.net> spoke thus:
Christopher Benson-Manica wrote:
Are the members of a struct guaranteed to have ascending memory
addresses?
Yes, always in C.


Just for my edification, what is the chapter and verse? Thanks...


In C90, it's 6.5.2.1, verse 11:

"Within a structure object, the non-bit-field members and the units in
which bit-fields reside have addresses that increase in the order in
which they are declared."

This is a bit vague, since you don't technically declare the units
bit-fields reside in (but rather the bit-fields that go in them, but
adjacent bits fields do go into each unit). Bit-field members within a
unit are in implementation-defined order.
--
Derrick Coetzee
I grant this newsgroup posting into the public domain. I disclaim all
express or implied warranty and all liability. I am not a professional.
Nov 14 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: John | last post by:
Hi all, Can a linked list be a member of a structure? If so, when I add or remove an element from the linked list, the size of the structure will change. Will it cause any problem? Thanks a...
19
by: Yoon Soo | last post by:
Hi, there while mixing assembler and c code I got the following question: struct bar { int bar_val1; int bar_val2; (...) }
11
by: Mannequin* | last post by:
Hi all, I'm working on a quick program to bring the Bible into memory from a text file. Anyway, I have three questions to ask. First, is my implementation of malloc () correct in the program to...
13
by: John | last post by:
In the course of an assignment, I learned the hard way that I shouldn't try to free a malloc'd member of a malloc'd structure after having freed that structure (i.e., free( structure ); free(...
2
by: Madhav | last post by:
Hi all, I was going through a piece of code which had a very interesting format. There were two files: one was a .h file, and the other was a .c file. The .c file had a structure defined in it...
2
by: Narendra | last post by:
void function1(void *); void main() { int size_offset = 0; typedef struct { int a; int b; int c; char ch;
8
by: rahul | last post by:
How is the memory allocated for structures? I need to optimize the memory usage and bit fields are not doing the trick. Any details about the memory allocation for the structures would be a...
5
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);"...
25
by: jbholman | last post by:
I am pretty new to C and doing my first project in C. I actually read almost the entire FAQ, but can't seem to figure out this problem. I have a structure. I have a list of these structures. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.