How to extract bytes from a long?

C

cody

Sheldon Simms said:
I did


I was so enthralled by the never-ending fights over whether people
have .signatures of the proper length, or have a valid email address
in their headers, or why one shouldn't use a nickname when posting,
etc., that I didn't have time to consider the grammar.


That's the reason why I as a german prefer to use english newsgroups instead
of german ones! There are so many stupid and irrelevant discussions about
proper capitalisation and realnames and so. Additionally I like english cos
I find it is more functional than german.
 
M

Mark McIntyre

struct { long lng} A;
struct { char byt[sizeof (long)] } B;
Does that apply to my struct too? Iam not really sure wheather long and
char[sizeof(long)] are compatible in this situation.

The answer is NO. Can you pass a char[] to a function expecting a
long? Can you pass a long to a function expecting a char? The standard
means what it says - the initial sequence of the two structs must be
identical in type.
If you find a mistake in my postings please said whats wrong do that i can
do it better next time.

Its "please say" rather than "please said". Said is the past tense.
Also please capitalise the letter i when used as the personal pronoun,
as I have done here.
 
C

cody

Mark McIntyre said:
struct { long lng} A;
struct { char byt[sizeof (long)] } B;
Does that apply to my struct too? Iam not really sure wheather long and
char[sizeof(long)] are compatible in this situation.

The answer is NO. Can you pass a char[] to a function expecting a
long? Can you pass a long to a function expecting a char? The standard
means what it says - the initial sequence of the two structs must be
identical in type.
If you find a mistake in my postings please said whats wrong do that i can
do it better next time.

Its "please say" rather than "please said". Said is the past tense.
Also please capitalise the letter i when used as the personal pronoun,
as I have done here.


Thx.
 
S

Serve La

> > > Isn't that what a union
is good for???
Stay with freeware. Don't even think about getting a paid job as a
programmer.

It can be far worse. I work with somebody who didn't even know C has unions.
 
J

Joe Wright

Serve said:
> > > Isn't that what a union
is good for???

It can be far worse. I work with somebody who didn't even know C has unions.

And dues-paying union members. :)
 
M

Mike Wahler

Serve La said:
> > > Isn't that what a union
is good for???

It can be far worse. I work with somebody who didn't even know C has
unions.

Hopefully he's not a member of a union as well. :)

-Mike
 
P

Peter Shaggy Haywood

Groovy hepcat cody was jivin' on Fri, 17 Oct 2003 00:23:18 +0200 in
comp.lang.c.
Re: How to extract bytes from a long?'s a cool scene! Dig it!
Eric Sosman said:
cody said:
Note the special guarantee:
[#5] With one exception, if the value of a member of a union
object is used when the most recent store to the object was
to a different member, the behavior is
implementation-defined.68) One special guarantee is made in
order to simplify the use of unions: If a union contains
several structures that share a common initial sequence (see
below), and if the union object currently contains one of
these structures, it is permitted to inspect the common
initial part of any of them anywhere that a declaration of
the completed type of the union is visible. Two structures
share a common initial sequence if corresponding members
have compatible types (and, for bit-fields, the same widths)
for a sequence of one or more initial members

The special guarantee applies only to union members
that happen to be structs, and only to structs if they
"share a common initial subsequence." The union you
exhibited contained no structs at all, and is not covered
by the special guarantee.

#include <stdio.h>
union X
{
struct { long lng} A;
struct { char byt[sizeof (long)] } B;
};

And now? Two structs with a common starting point.

Yes, but no common initial sequence. Both of these structures
contain completely different data types. They have nothing in common,
except their starting address. But that's not what the above passage
is about.
I try my best :)


That is correct, I'm german.


I didn't know grammar of American and British is different.

Who said they're different? Eric said there were gammatical errors,
not differences in (correct) grammar. And I think it was a
tongue-in-cheek slight at the Yanks. :)
Honestly, not a simple task. :)

Even for those of us with a good grasp on English grammar.

--

Dig the even newer still, yet more improved, sig!

http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top