standard posix wants a cast

B

Bill Cunningham

On this page:

http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/socket.h.html

The sockaddr_storage struct is to be cast as a sockaddr. I can think of
another way to do it being designing another struct object, would that be
considered the proper way to use the sort of programming I am looking at. I
came into C with one thing in mind. No casts. I am assuming this is safe
since the standard asks for this. Should I ignore the standard and rewrite
not using casts or is this considered an exception to the rule?

Bill
 
N

Nick Keighley

    On this page:

http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/socket.h.html

The sockaddr_storage struct is to be cast as a sockaddr.

near the beginning of the page "When a sockaddr_storage structure is
cast as a sockaddr structure..."
I can think of
another way to do it being designing another struct object,
what?

would that be
considered the proper way to use the sort of programming I am looking at.

wait I have a vision! I see clearly now. No, my clairvoyance has gone.
How am I supposed to know what sort of programming you are loooking
at?
I came into C with one thing in mind. No casts.

that was silly wasn't it? Casts are a tool in your toolkit. They are
often over used but they are also often useful. Low level comms stuff
(like sockets) often finds legitimate uses for them. If you have a
work around or a programming style that doesn't need the casts then go
for it. But be careful the Posix people aren't stupid.
I am assuming this is safe since the standard asks for this.

the C standard doesn't

Should I ignore the standard and rewrite
not using casts or is this considered an exception to the rule?

there is no rule. Ask on a Unix group this isn't standard C


--
Casting is almost always wrong,
and the places where it's right are rarely the places you'd guess.
Richard Heathfield

Abuse of casting leads to abuse of the type system
leads to sloppy programming leads to
unreliably, even undefined, behaviour.
And that is the path to the dark side....
Richard Bos/John Hascall
 
B

Bill Cunningham

On this page:

http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/socket.h.html

The sockaddr_storage struct is to be cast as a sockaddr.

near the beginning of the page "When a sockaddr_storage structure is
cast as a sockaddr structure..."
I can think of
another way to do it being designing another struct object,

what?

I thought I was clear. Maybe not. Click the link.
would that be
considered the proper way to use the sort of programming I am looking at.

wait I have a vision! I see clearly now. No, my clairvoyance has gone.
How am I supposed to know what sort of programming you are loooking
at?

No clairvoyance needed. Just click the link.
I came into C with one thing in mind. No casts.

that was silly wasn't it? Casts are a tool in your toolkit. They are
often over used but they are also often useful. Low level comms stuff
(like sockets) often finds legitimate uses for them. If you have a
work around or a programming style that doesn't need the casts then go
for it. But be careful the Posix people aren't stupid.

I see.

I am assuming this is safe since the standard asks for this.

the C standard doesn't

Should I ignore the standard and rewrite
not using casts or is this considered an exception to the rule?

there is no rule. Ask on a Unix group this isn't standard C

I thought it was. Casting is in any C.
--
Casting is almost always wrong,
and the places where it's right are rarely the places you'd guess.
Richard Heathfield

Abuse of casting leads to abuse of the type system
leads to sloppy programming leads to
unreliably, even undefined, behaviour.
And that is the path to the dark side....
Richard Bos/John Hascall

OK that makes sense.
 
K

Keith Thompson

Bill Cunningham said:
near the beginning of the page "When a sockaddr_storage structure is
cast as a sockaddr structure..."


what?

I thought I was clear. Maybe not. Click the link.
[snip]

Bill, you need to change newsreaders. Outlook Express isn't handling
quoted text properly. I seem to recall that you tried "quotefix",
and it didn't work.

You briefly used Thunderbird on January 8; is there any reason you
can't just use it from now on?
 
B

Bill Cunningham

Bill, you need to change newsreaders. Outlook Express isn't handling
quoted text properly. I seem to recall that you tried "quotefix",
and it didn't work.

You briefly used Thunderbird on January 8; is there any reason you
can't just use it from now on?

No I suppose I can go back to thunderbird.

Bill
 
E

Eric Sosman

[...]
near the beginning of the page "When a sockaddr_storage structure is
cast as a sockaddr structure..."

Interesting choice of words, since a C compiler is required
to emit a diagnostic if any cast operator other than (void) is
applied to a struct ...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,772
Messages
2,569,593
Members
45,111
Latest member
VetaMcRae
Top