Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > structure address = structure first field address ?

Reply
Thread Tools

structure address = structure first field address ?

 
 
Tony
Guest
Posts: n/a
 
      05-19-2009

"Keith Thompson" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> "Tony" <(E-Mail Removed)> writes:
> [...]
>> I rely on the fact that the compiler gives some kind of padding/alignment
>> control, either via pragmas or commandline/IDE switches. I pretty much
>> byte-align everything (with the switch) and do "manual alignment" when
>> designing structs (not as hard as it sounds). The only real "gotcha" to
>> watch out for is pointer fields for their width is different on 32- and
>> 64-bit platforms (put pointers at the top of the struct and subsequent
>> field
>> will align nicely). I always use width-specified integral types.

>
> Why? Is it really worth the effort to do manually what the compiler
> would have done for you?


Yes, as an aspiring compiler writer it does. Also, having complete control
of your code is important: read, the portability mantra is a white elephant
(or yet to be one). All those behind the scenes things the compiler does
get's annoying many times (moreso in C++, but there, one thing leads to
another and that makes it a big pill), and I have different goals for my
language that the C language has.

Tony



 
Reply With Quote
 
 
 
 
Tony
Guest
Posts: n/a
 
      05-19-2009

"blargg" <(E-Mail Removed)> wrote in message
news:blargg.ei3-0205091330460001@192.168.1.4...
> Keith Thompson wrote:
>> "Tony" <(E-Mail Removed)> writes:
>> [...]
>> > I rely on the fact that the compiler gives some kind of
>> > padding/alignment
>> > control, either via pragmas or commandline/IDE switches. I pretty much
>> > byte-align everything (with the switch) and do "manual alignment" when
>> > designing structs (not as hard as it sounds). The only real "gotcha" to
>> > watch out for is pointer fields for their width is different on 32- and
>> > 64-bit platforms (put pointers at the top of the struct and subsequent

> field
>> > will align nicely). I always use width-specified integral types.

>>
>> Why? Is it really worth the effort to do manually what the compiler
>> would have done for you?

>
> The compiler won't reorder members of a struct to reduce space wasted by
> padding. If one is going to create millions of objects of some structure
> type and wants to reduce padding in a portable way, he should order
> members from largest to smallest, for example double, long long, pointers,
> long, float, int, short, char.


I rather have control via a switch or pragma rather than "a portable way".

Tony


 
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
Iterate through a list of structure arrays of structure to get outthe field stuie_norris@yahoo.com.au C Programming 2 12-12-2012 09:18 PM
javascript validation for a not required field, field is onlyrequired if another field has a value jr Javascript 3 07-08-2010 10:33 AM
1.Enter space bar for field names and save the field.The field shoud not get saved and an alert should be there as"Space bars are not allowed" Sound Javascript 2 09-28-2006 02:43 PM
Parent first or child first? (a class structure question) Tony Young C++ 3 03-26-2006 12:59 AM
20D's first field trip. First Snake of Spring Celtic Boar Digital Photography 3 04-10-2005 09:40 PM



Advertisments