* Re: Writing portable Code for Glibc and 32/64 bit
@ 1998-11-21 20:51 Greg Lindahl
0 siblings, 0 replies; 8+ messages in thread
From: Greg Lindahl @ 1998-11-21 20:51 UTC (permalink / raw)
To: axp-list
> Yeh - but what about the size of int's and all the possible alignment
> issues in a more general case.
You can't solve the general case without a bit more work, which is
probably unnecessary: compile a test program with this structure in
it, and print out the size. Then start adding various padding
variables and see when you get what you want. That's the kind of thing
that configure helps you out with.
-- g
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Writing portable Code for Glibc and 32/64 bit
@ 1998-11-21 20:12 Greg Lindahl
1998-11-21 20:40 ` Dave Gilbert
0 siblings, 1 reply; 8+ messages in thread
From: Greg Lindahl @ 1998-11-21 20:12 UTC (permalink / raw)
To: axp-list
> A portability problem I have tried to figure out a good soloution for is
> that of structure sizes in arrays - e.g.
>
> struct frob {
> void *a;
> void *b;
> int x;
> int dummy;
#ifdef PTRS_ARE_64_BITS
void *__ignore_me;
#endif
> }
However, I would first prove to myself that it makes a significant
difference in the run-time of my program to waste all that memory. And
it's hard to believe that this is worth hacking the compiler chain to
do this kind of thing for other people.
-- g
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Writing portable Code for Glibc and 32/64 bit
1998-11-21 20:12 Greg Lindahl
@ 1998-11-21 20:40 ` Dave Gilbert
1998-11-21 20:47 ` Maciej W. Rozycki
0 siblings, 1 reply; 8+ messages in thread
From: Dave Gilbert @ 1998-11-21 20:40 UTC (permalink / raw)
To: axp-list
On Sat, 21 Nov 1998, Greg Lindahl wrote:
That I wrote:
> > A portability problem I have tried to figure out a good soloution for is
> > that of structure sizes in arrays - e.g.
> >
> > struct frob {
> > void *a;
> > void *b;
> > int x;
> > int dummy;
> #ifdef PTRS_ARE_64_BITS
> void *__ignore_me;
> #endif
> > }
Yeh - but what about the size of int's and all the possible alignment
issues in a more general case.
> However, I would first prove to myself that it makes a significant
> difference in the run-time of my program to waste all that memory. And
Sure.
> it's hard to believe that this is worth hacking the compiler chain to
> do this kind of thing for other people.
Oh yeh - I don't think it warrants a compiler chain change; I just want to
know how to write it generically in the source.
Dave
--------------------------------------------------------------------
/ Dr. David Alan Gilbert | Running Linux on Alpha(LX) | Happy \
\ gro.gilbert @ treblig.org | & ARM(EBSA285,old Arc) | In Hex /
\____________________________|___ http://www.treblig.demon.co.uk __/
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Writing portable Code for Glibc and 32/64 bit
1998-11-21 20:40 ` Dave Gilbert
@ 1998-11-21 20:47 ` Maciej W. Rozycki
0 siblings, 0 replies; 8+ messages in thread
From: Maciej W. Rozycki @ 1998-11-21 20:47 UTC (permalink / raw)
To: axp-list
> > > struct frob {
> > > void *a;
> > > void *b;
> > > int x;
> > > int dummy;
> > #ifdef PTRS_ARE_64_BITS
> > void *__ignore_me;
> > #endif
> > > }
>
> Yeh - but what about the size of int's and all the possible alignment
> issues in a more general case.
Just use a union of void * and int (or whatever type you need).
--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +
^ permalink raw reply [flat|nested] 8+ messages in thread
* Writing portable Code for Glibc and 32/64 bit
@ 1998-11-20 11:03 y0000218
1998-11-20 15:02 ` Stefan Schroepfer
0 siblings, 1 reply; 8+ messages in thread
From: y0000218 @ 1998-11-20 11:03 UTC (permalink / raw)
Hi,
for a friend that has to implement transparent network cryptography for
Linux soon: Where can I find documents that tell him how to code
good, portable code for glibc and 32/64 bit Linux? It there a quick
introductory paper to the most important things to remember and a longer
one explaning what to do and what not?
Thanks for any hints,
Olaf
--
"The number of Unix installations Olaf Schnapauff,
has grown to 10, with more expected." O.Schnapauff@tu-bs.de
- The Unix Programmer's Manual,1972 http://www.tu-bs.de/~c0033014/
See Web page and keyservers for pgp public key
^ permalink raw reply [flat|nested] 8+ messages in thread* Re: Writing portable Code for Glibc and 32/64 bit
1998-11-20 11:03 y0000218
@ 1998-11-20 15:02 ` Stefan Schroepfer
1998-11-20 18:53 ` Jeff DeMaagd
0 siblings, 1 reply; 8+ messages in thread
From: Stefan Schroepfer @ 1998-11-20 15:02 UTC (permalink / raw)
To: axp-list
I'm not aware of a paper, but the following rules may serve as a
starting point:
- Don't store pointers in ints (it should be safe to use unsigned
longs for this purpose, but why not use pointer variables).
- Don't make assumptions on the size of data types, always use
the sizeof () operator.
- Avoid assembly language.
scr
y0000218@rzsrv2.rz.tu-bs.de wrote:
>
> for a friend that has to implement transparent network cryptography for
> Linux soon: Where can I find documents that tell him how to code
> good, portable code for glibc and 32/64 bit Linux? It there a quick
> introductory paper to the most important things to remember and a longer
> one explaning what to do and what not?
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Writing portable Code for Glibc and 32/64 bit
1998-11-20 15:02 ` Stefan Schroepfer
@ 1998-11-20 18:53 ` Jeff DeMaagd
1998-11-21 13:18 ` Dave Gilbert
0 siblings, 1 reply; 8+ messages in thread
From: Jeff DeMaagd @ 1998-11-20 18:53 UTC (permalink / raw)
To: axp-list
On Fri, 20 Nov 1998, Stefan Schroepfer wrote:
> I'm not aware of a paper, but the following rules may serve as a
> starting point:
> - Don't store pointers in ints (it should be safe to use unsigned
> longs for this purpose, but why not use pointer variables).
Rather goofy that a compiler ever lets that happen. So much for the goal
of 'easy portability'. Goofier yet is that people that think themselves
as competent programmers do this.
> - Don't make assumptions on the size of data types, always use
> the sizeof () operator.
Oh, that's why it's in the language! :)
> - Avoid assembly language.
I don't mind assembly language, just make sure there are IFNDEF's for
general purpose code too. Makes maintainance a bit harder, but sometimes
raw performance matters. :)
> > for a friend that has to implement transparent network cryptography for
> > Linux soon: Where can I find documents that tell him how to code
> > good, portable code for glibc and 32/64 bit Linux? It there a quick
> > introductory paper to the most important things to remember and a longer
> > one explaning what to do and what not?
JRDM
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Writing portable Code for Glibc and 32/64 bit
1998-11-20 18:53 ` Jeff DeMaagd
@ 1998-11-21 13:18 ` Dave Gilbert
0 siblings, 0 replies; 8+ messages in thread
From: Dave Gilbert @ 1998-11-21 13:18 UTC (permalink / raw)
To: axp-list
A portability problem I have tried to figure out a good soloution for is
that of structure sizes in arrays - e.g.
struct frob {
void *a;
void *b;
int x;
int dummy;
}
Now that isn't unreasonable is it? Size on 32 bit machine 16, size on
64 bit machine 24.
The problem is that say I made a big array out of those, and you want to
make sure that the compiler uses shift rather than multiply to address it.
This will happen on the 32 bit machine but not the 64 because of the
non-power of 2 size.
How does one write a structure of a mixture of pointers and ints etc while
guarenteeing it will be a power of 2 in size?
Dave
--------------------------------------------------------------------
/ Dr. David Alan Gilbert | Running Linux on Alpha(LX) | Happy \
\ gro.gilbert @ treblig.org | & ARM(EBSA285,old Arc) | In Hex /
\____________________________|___ http://www.treblig.demon.co.uk __/
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~1998-11-21 20:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1998-11-21 20:51 Writing portable Code for Glibc and 32/64 bit Greg Lindahl
-- strict thread matches above, loose matches on Subject: below --
1998-11-21 20:12 Greg Lindahl
1998-11-21 20:40 ` Dave Gilbert
1998-11-21 20:47 ` Maciej W. Rozycki
1998-11-20 11:03 y0000218
1998-11-20 15:02 ` Stefan Schroepfer
1998-11-20 18:53 ` Jeff DeMaagd
1998-11-21 13:18 ` Dave Gilbert
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox