This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: bluesky idea: __attribute__ (netorder)
- To: egcs at tantalophile dot demon dot co dot uk (Jamie Lokier)
- Subject: Re: bluesky idea: __attribute__ (netorder)
- From: Tim Hollebeek <tim at wagner dot princeton dot edu>
- Date: Sun, 6 Sep 1998 11:02:13 -0400 (EDT)
- Cc: carlo at runaway dot xs4all dot nl, weejock at ferret dot lmh dot ox dot ac dot uk, egcs at cygnus dot com
Jamie Lokier writes ...
>
> On Sat, Sep 05, 1998 at 03:31:05AM +0200, Carlo Wood wrote:
> > | Perhaps __a__ ({big,little}endian) might make more sense...
Not this thread again ...
> How about generalising this feature to support arbitrary markers, which
> must match up when a value is moved around otherwise a warning it
> produced?
You mean instead of variables just having values, they also have types?
What a novel concept.
There are hundreds of ways to do this that do not include modifying the compiler and writing nonstandard C/C++. For example:
---
typedef struct {
short v;
} network_short_t;
typedef struct {
network_short_t sin_port;
/* ... */
} socket_address_t;
inline unsigned short network_to_host_short(network_short_t n) {
return ntohs(n.v);
}
inline network_short_t host_to_network_short(unsigned short us) {
network_short_t n;
n.v = htons(us);
return n;
}
int main() {
socket_address_t sa;
unsigned short x = sa.sin_port;
return 0;
}