This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: bluesky idea: __attribute__ (netorder)


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;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]