Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > producing the memory layout you really want is non-portable anddeprecated

Reply
Thread Tools

producing the memory layout you really want is non-portable anddeprecated

 
 
aarklon@gmail.com
Guest
Posts: n/a
 
      04-10-2008
Hi,

I used to argue at this point that using memory-mapped IO made it
easier to write device drivers in C, since you could map devices to C
structures. Unfortunately, modern C compilers pad structures for
performance reasons, and trying to coerce the compiler into producing
the memory layout you really want is non-portable and deprecated. So
I'm leaving the argument in place, but it's really for historical
interest at this point. The comments about trying to create in and out
instructions do remain valid, however.

Also, when writing device drivers in C, it's a lot easier to work
with when devices are in memory space. Let's suppose you have a simple
device (for concreteness, let's look at the A/D convertor on an HC11.
It's controlled by five registers (not counting the OPTION register),
located at addresses $1030-$1034. We can define a struct that looks
like this:

see:- http://www.cs.nmsu.edu/~pfeiffer/cla.../notes/io.html
 
Reply With Quote
 
 
 
 
Richard
Guest
Posts: n/a
 
      04-10-2008
http://www.velocityreviews.com/forums/(E-Mail Removed) writes:

> Hi,
>
> I used to argue at this point that using memory-mapped IO made it
> easier to write device drivers in C, since you could map devices to C
> structures. Unfortunately, modern C compilers pad structures for
> performance reasons, and trying to coerce the compiler into producing
> the memory layout you really want is non-portable and deprecated. So
> I'm leaving the argument in place, but it's really for historical
> interest at this point. The comments about trying to create in and out
> instructions do remain valid, however.
>
> Also, when writing device drivers in C, it's a lot easier to work
> with when devices are in memory space. Let's suppose you have a simple
> device (for concreteness, let's look at the A/D convertor on an HC11.
> It's controlled by five registers (not counting the OPTION register),
> located at addresses $1030-$1034. We can define a struct that looks
> like this:
>
> see:- http://www.cs.nmsu.edu/~pfeiffer/cla.../notes/io.html


Which begs the question : since people have known for a long time that C
was going to be used primarily for embedded systems in the future, why
oh why is the support for non padded structures so bad? Sure some
compilers have a pragma to remove padding but thats not "standard".

The FAQ says this:

http://c-faq.com/struct/padding.html

I would be interested in seeing a general approach to this

,----
| If you're worried about wasted space, you can minimize the effects of padding by ordering the members of a structure based on their base types, from largest to smallest.
`----

that is "standards compliant" and not "hard coded".

 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      04-10-2008
Richard wrote:
>
> Which begs the question : since people have known for a long time that C
> was going to be used primarily for embedded systems in the future, why
> oh why is the support for non padded structures so bad? Sure some
> compilers have a pragma to remove padding but thats not "standard".
>

Every embedded compiler (ant that's quite a lot!) I've used supported
packed structures. I certainly would think many times about using one
that didn't.

--
Ian Collins.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      04-10-2008
Ian Collins <(E-Mail Removed)> writes:

> Richard wrote:
>>
>> Which begs the question : since people have known for a long time that C
>> was going to be used primarily for embedded systems in the future, why
>> oh why is the support for non padded structures so bad? Sure some
>> compilers have a pragma to remove padding but thats not "standard".
>>

> Every embedded compiler (ant that's quite a lot!) I've used supported
> packed structures. I certainly would think many times about using one
> that didn't.


Is the pragma line itself "standard"?
 
Reply With Quote
 
Ian Collins
Guest
Posts: n/a
 
      04-10-2008
Richard wrote:
> Ian Collins <(E-Mail Removed)> writes:
>
>> Richard wrote:
>>> Which begs the question : since people have known for a long time that C
>>> was going to be used primarily for embedded systems in the future, why
>>> oh why is the support for non padded structures so bad? Sure some
>>> compilers have a pragma to remove padding but thats not "standard".
>>>

>> Every embedded compiler (ant that's quite a lot!) I've used supported
>> packed structures. I certainly would think many times about using one
>> that didn't.

>
> Is the pragma line itself "standard"?


Don't be silly, how can you standardise something a lot of machines
can't do?

--
Ian Collins.
 
Reply With Quote
 
Richard
Guest
Posts: n/a
 
      04-10-2008
Ian Collins <(E-Mail Removed)> writes:

> Richard wrote:
>> Ian Collins <(E-Mail Removed)> writes:
>>
>>> Richard wrote:
>>>> Which begs the question : since people have known for a long time that C
>>>> was going to be used primarily for embedded systems in the future, why
>>>> oh why is the support for non padded structures so bad? Sure some
>>>> compilers have a pragma to remove padding but thats not "standard".
>>>>
>>> Every embedded compiler (ant that's quite a lot!) I've used supported
>>> packed structures. I certainly would think many times about using one
>>> that didn't.

>>
>> Is the pragma line itself "standard"?

>
> Don't be silly, how can you standardise something a lot of machines
> can't do?


It could stop the compilation? Hence standard code base.
 
Reply With Quote
 
Philip Potter
Guest
Posts: n/a
 
      04-10-2008
Ian Collins wrote:
> Richard wrote:
>> Ian Collins <(E-Mail Removed)> writes:
>>
>>> Richard wrote:
>>>> Which begs the question : since people have known for a long time that C
>>>> was going to be used primarily for embedded systems in the future, why
>>>> oh why is the support for non padded structures so bad? Sure some
>>>> compilers have a pragma to remove padding but thats not "standard".
>>>>
>>> Every embedded compiler (ant that's quite a lot!) I've used supported
>>> packed structures. I certainly would think many times about using one
>>> that didn't.

>> Is the pragma line itself "standard"?

>
> Don't be silly, how can you standardise something a lot of machines
> can't do?


The same way you standardise IEEE floating point - that is, make it an
optional part of the standard.

Philip
 
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
I really need help with this so if anyone can help me out that wouldbe really great of you. adityagaddam90@gmail.com Java 30 02-10-2008 11:29 PM
HSQLDB in memory DB producing local files ... lbrtchx@hotmail.com Java 5 10-29-2006 10:32 PM
Choosing Layout: Css-Layout or Table-Layout hpourfard@gmail.com ASP .Net 1 06-19-2006 10:06 AM
If you really want to help... easy, and still feel good dave warren Computer Support 0 02-08-2006 11:55 PM
DataList inside a Grid Layout Panel (<DIV>) item layout problem Rick Spiewak ASP .Net 3 08-26-2003 04:22 AM



Advertisments