By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,665 Members | 1,258 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,665 IT Pros & Developers. It's quick & easy.

passing a union's field to a function

P: n/a
Hello!

The sample program below is compiled fine by gcc (with -Wall), but rejected
by Sun's SUNWspro compiler (version 6 update 2).

The point of contention is, whether a value for one of the union's types can
be passed to a function directly -- without creating a separate variable of
the union type and assigning the appropriate field of it.

Is gcc being too liberal, or is this behavior simply part of a newer
C-standard, which Sun's old compiler is not supporting? Thanks!

-mi
Aug 11 '06 #1
Share this Question
Share on Google+
50 Replies


P: n/a
Mikhail Teterin said:
Hello!

The sample program below is compiled fine by gcc (with -Wall), but
rejected by Sun's SUNWspro compiler (version 6 update 2).
What sample program?
The point of contention is, whether a value for one of the union's types
can be passed to a function directly -- without creating a separate
variable of the union type and assigning the appropriate field of it.
The value of the most recently assigned union member object can be passed to
a function directly. There is no need to copy it out.
Is gcc being too liberal, or is this behavior simply part of a newer
C-standard, which Sun's old compiler is not supporting? Thanks!
Who knows? I don't see your code.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 11 '06 #2

P: n/a
Richard Heathfield wrote:
What sample program?
Your news-reader must be doing something nasty with attachments.

The program was attached to the original posting. Here it is inline.

-mi

#include <stdio.h>

typedef union {
ššššššššintššššši;
ššššššššvoidšššš*p;
ššššššššstruct {
ššššššššššššššššintššššši;
ššššššššššššššššintšššššj;
šššššššš}šššššššs;
} testunion;

static void
testfunc(testunion u)
{
ššššššššprintf("i: %d\np: %p\n", u.i, u.p);
}

int
main()
{
šššššššštestfunc((testunion)3);
šššššššštestfunc((testunion)NULL);
ššššššššreturn 0;
}
Aug 11 '06 #3

P: n/a
Mikhail Teterin said:
Richard Heathfield wrote:
>What sample program?

Your news-reader must be doing something nasty with attachments.
Attachments don't happen in comp.lang.c - it's a text-only newsgroup.
#include <stdio.h>

typedef union {
int i;
void *p;
struct {
int i;
int j;
} s;
} testunion;

static void
testfunc(testunion u)
{
printf("i: %d\np: %p\n", u.i, u.p);
Either you put in an int, in which case it's okay to print the int but not
the void *, or you put in a void *, in which case it's okay to print the
void * but not the int.
}

int
main()
{
testfunc((testunion)3);
That's not a valid conversion.
testfunc((testunion)NULL);
Neither is that.
return 0;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 11 '06 #4

P: n/a
Richard Heathfield wrote:
Attachments don't happen in comp.lang.c - it's a text-only newsgroup.
Mine was a text-only attachement. And I can see it on my news-server...
Mikhail Teterin said:
>testfunc((testunion)3);

That's not a valid conversion.
But gcc has no problem with it, and my question was: "why?" Is gcc too lax,
or is it aware of a newer C-standard that neither then Sun's compiler nor
you are aware of?

If a function expects a union, one of whose fields is `int':

typedef union {
int i;
void *p;
struct {
int i;
int j;
} s;
} testunion;

then passing an integer argument (with or without casting) is quite
unambigious -- gcc's treatment seems perfectly reasonable to me...

-mi
Aug 11 '06 #5

P: n/a
Mikhail Teterin <us****@aldan.algebra.comwrites:
The sample program below is compiled fine by gcc (with -Wall), but rejected
by Sun's SUNWspro compiler (version 6 update 2).

The point of contention is, whether a value for one of the union's types can
be passed to a function directly -- without creating a separate variable of
the union type and assigning the appropriate field of it.

Is gcc being too liberal, or is this behavior simply part of a newer
C-standard, which Sun's old compiler is not supporting? Thanks!

#include <stdio.h>

typedef union {
int i;
void *p;
struct {
int i;
int j;
} s;
} testunion;

static void
testfunc(testunion u)
{
printf("i: %d\np: %p\n", u.i, u.p);
}

int
main()
{
testfunc((testunion)3);
testfunc((testunion)NULL);
return 0;
}
Your program appeared in my newsreader as an attachment. Please don't
post attachments here; just copy your source code into the text of
your article.

You can't cast to a union type in either C90 or C99. gcc apparently
provides this as an extension. This is mentioned in the "C
Extensions" section of the gcc documentation. That documentation will
also tell you about the "-ansi -pedantic" or, if you prefer, "-std=c99
-pedantic" options, which would have warned you about this.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 11 '06 #6

P: n/a
Mikhail Teterin wrote:
Richard Heathfield wrote:

>>Attachments don't happen in comp.lang.c - it's a text-only newsgroup.


Mine was a text-only attachement. And I can see it on my news-server...
Doesn't matter, text-only newsgroups don't forward attachments.
>
>>Mikhail Teterin said:
>>>testfunc((testunion)3);

That's not a valid conversion.


But gcc has no problem with it, and my question was: "why?" Is gcc too lax,
or is it aware of a newer C-standard that neither then Sun's compiler nor
you are aware of?
In default mode, gcc will compile just about anything remotely like C.

gcc -Wall -pedantic -ansi /tmp/x.c
/tmp/x.c: In function `main':
/tmp/x.c:21: warning: ISO C forbids casts to union type
/tmp/x.c:22: warning: ISO C forbids casts to union type

Compile with an appropriate warning level, you'll learn more that way.

--
Ian Collins.
Aug 11 '06 #7

P: n/a
Ian Collins wrote:
Mikhail Teterin wrote:
>>Richard Heathfield wrote:
>>>Attachments don't happen in comp.lang.c - it's a text-only newsgroup.


Mine was a text-only attachement. And I can see it on my news-server...

Doesn't matter, text-only newsgroups don't forward attachments.
Oops, got that one wrong. It did....

--
Ian Collins.
Aug 11 '06 #8

P: n/a
Mikhail Teterin <us****@aldan.algebra.comwrites:
Richard Heathfield wrote:
>What sample program?

Your news-reader must be doing something nasty with attachments.

The program was attached to the original posting. Here it is inline.
Ugh, that's worse. In my newsreader, it shows up with a bunch of
non-printable '\232' characters.

I don't know how they got there, but try to use only spaces for
indentation. Copy and paste plain text if you can.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 11 '06 #9

P: n/a
Ian Collins wrote:
In default mode, gcc will compile just about anything remotely like C.
I'm compiled with -Wall, not default, although I don't use -pedantic.
gcc -Wall -pedantic -ansi /tmp/x.c
/tmp/x.c: In function `main':
/tmp/x.c:21: warning: ISO C forbids casts to union type
/tmp/x.c:22: warning: ISO C forbids casts to union type

Compile with an appropriate warning level, you'll learn more that way.
With -Wall, but without -pedantic, the code still compiles cleanly and works
as expected:

% gcc -Wall -o union union.c
% ./union
i: 3
p: 3
i: 0
p: 0

Adding "-pedantic" does, indeed, elicit warnings you quote. So, is there a
way to pass a value to a union-expecting function, without creating a union
and copying the values around, as in:

testunion t;

t.i = i;
testfunc(t);

Why can't I just do:

testfunc(i)

? Is there any kind of ambiguity here?

The reason, I'm so insistant is not only having to copy values around and
create (seemingly) useless local variables. It is also that Purify reports
such passing of unions as a UMR (Uninitialized Memory Read), because other
(longer) fields of the union remain unitilized (such as the s.j field in my
sample union) and putting them onto stack (for a function call)
means "reading" them...

Thanks,

-mi
Aug 11 '06 #10

P: n/a
Keith Thompson wrote:
Ugh, that's worse. In my newsreader, it shows up with a bunch of
non-printable '\232' characters.
I just saved it back to a file from the news-reader. The file is perfectly
clean, opens up fine in vi, and compiles...
I don't know how they got there, but try to use only spaces for
indentation. šCopy and paste plain text if you can.
BSD's style(9) mandates use of tabs for indentation :-)

http://www.freebsd.org/cgi/man.cgi?q...tyle&sektion=9

Yours,

-mi
Aug 11 '06 #11

P: n/a
Keith Thompson wrote:
Your program appeared in my newsreader as an attachment. Please don't
post attachments here
Why? Is not a (text) attachement easier to deal with? None of the "---- cut
here ---" nuissance, just save into a file and compile...
You can't cast to a union type in either C90 or C99. gcc apparently
provides this as an extension. This is mentioned in the "C
Extensions" section of the gcc documentation. That documentation will
also tell you about the "-ansi -pedantic" or, if you prefer, "-std=c99
-pedantic" options, which would have warned you about this.
Thanks for the most useful answer... Any ideas on why this is not part of
the C-standard (yet?)? What's wrong with this extension -- what does it
break? Yours,

-mi
Aug 11 '06 #12

P: n/a
Mikhail Teterin wrote:
Keith Thompson wrote:
Ugh, that's worse. In my newsreader, it shows up with a bunch of
non-printable '\232' characters.

I just saved it back to a file from the news-reader. The file is perfectly
clean, opens up fine in vi, and compiles...
Well, your "inline" version looks like crap on Google Groups as well,
take a look for yourself if you'd like.
I don't know how they got there, but try to use only spaces for
indentation. šCopy and paste plain text if you can.

BSD's style(9) mandates use of tabs for indentation :-)

http://www.freebsd.org/cgi/man.cgi?q...tyle&sektion=9
Perhaps you don't realize it but this is Usenet, not the BSD kernel.
Spaces are the recommended method of indentation here and for good
reason.

Robert Gamble

Aug 11 '06 #13

P: n/a
Mikhail Teterin wrote:
>
Adding "-pedantic" does, indeed, elicit warnings you quote. So, is there a
way to pass a value to a union-expecting function, without creating a union
and copying the values around, as in:

testunion t;

t.i = i;
testfunc(t);

Why can't I just do:

testfunc(i)

? Is there any kind of ambiguity here?
Think of your union as an object. If you had written

typedef struct { int n; } X;

void testFn( X x ) {}

You wouldn't expect to be able to pass an int to testFn, same when the
parameter is a union.
The reason, I'm so insistant is not only having to copy values around and
create (seemingly) useless local variables.
Why worry? Let the compiler take care of optimising away local variables.
It is also that Purify reports
such passing of unions as a UMR (Uninitialized Memory Read), because other
(longer) fields of the union remain unitilized (such as the s.j field in my
sample union) and putting them onto stack (for a function call)
means "reading" them...
What else did you expect?

Using unions as function parameters is not a good idea in my opinion.
If you do, I'd recommend wrapping them in a simple struct with a member
used to indicate which member of the union is being passed:

typedef union {
int i;
void *p;
struct {
int i;
int j;
} s;
} testunion;
typedef struct {
enum { Int, Void, Struct} key;
testunion value;
} X;

static void testfunc( X* x ){}

int main(void)
{
X x;
x.key = Int;
x.value.i = 42;

testfunc( &x );

return 0;
}

--
Ian Collins.
Aug 11 '06 #14

P: n/a
Mikhail Teterin wrote:
Keith Thompson wrote:

>>Your program appeared in my newsreader as an attachment. Please don't
post attachments here


Why? Is not a (text) attachement easier to deal with? None of the "---- cut
here ---" nuissance, just save into a file and compile...
Some people use news readers that don't support attachments. On Usenet,
go for the lowest common denominator, plain text.

--
Ian Collins.
Aug 11 '06 #15

P: n/a
Ian Collins wrote:
>>>Your program appeared in my newsreader as an attachment. Please don't
post attachments here

Why? Is not a (text) attachement easier to deal with? None of the "----
cut here ---" nuissance, just save into a file and compile...
Some people use news readers that don't support attachments. On Usenet,
go for the lowest common denominator, plain text.
Come on -- that's not a valid argument. The attachements have appeared more
than 10 years ago and all news-readers (including text based ones) now
support them.

A text-only attachement is no different, really from a "--- cut here ---" --
look at the "body" of my original message to see, what I mean. It is not
encoded, and the reader is not expected to render any images. One could
telnet to port 119, speak NNTP to get the article and would *still* get the
posted textual attachment correctly...

-mi

Aug 11 '06 #16

P: n/a
Robert Gamble wrote:
Perhaps you don't realize it but this is Usenet, not the BSD kernel.
Spaces are the recommended method of indentation here and for good
reason.
The reason being?..

-mi
Aug 11 '06 #17

P: n/a
Mikhail Teterin <us****@aldan.algebra.comwrites:
Keith Thompson wrote:
>Your program appeared in my newsreader as an attachment. Please don't
post attachments here

Why? Is not a (text) attachement easier to deal with? None of the "---- cut
here ---" nuissance, just save into a file and compile...
No, it isn't. At least one responder said his newsreader didn't even
show him the attachment. Each newsreader handles attachments in its
own way, and they're strongly discouraged in discussion groups.

The "--- cut here ---" stuff is easy enough to handle.
>You can't cast to a union type in either C90 or C99. gcc apparently
provides this as an extension. This is mentioned in the "C
Extensions" section of the gcc documentation. That documentation will
also tell you about the "-ansi -pedantic" or, if you prefer, "-std=c99
-pedantic" options, which would have warned you about this.

Thanks for the most useful answer... Any ideas on why this is not part of
the C-standard (yet?)? What's wrong with this extension -- what does it
break?
There are an unlimited number of things that could be added to the
standard. If they were all added, a copy of the standard would be too
heavy to lift. New features shouldn't be added to the core language
just for the sake of a minor convenience.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 11 '06 #18

P: n/a
Ian Collins wrote:
>? Is there any kind of ambiguity here?
Think of your union as an object. If you had written

typedef struct { int n; } X;

void testFn( X x ) {}

You wouldn't expect to be able to pass an int to testFn, same when the
parameter is a union.
But I don't think of it as an object -- not in this case. It is just a way
to pass a different type of argument to the same function (without the mess
of varargs/stdargs).
>The reason, I'm so insistant is not only having to copy values around and
create (seemingly) useless local variables.

Why worry? Let the compiler take care of optimising away local variables.
The code looks ugly -- with many extra lines. It also requires the caller to
know about the union's internals, when all it needs to know, is that it
passes a number.
>It is also that Purify reports such passing of unions as a UMR
(Uninitialized Memory Read), because other (longer) fields of the union
remain unitilized (such as the s.j field in my sample union) and putting
them onto stack (for a function call) means "reading" them...
What else did you expect?
Well, I expect Purify to tell me about *real* problems in the code... Having
been alerted to this by Purify, I tried to come up with a better
replacement for the alarm-triggering code...
Using unions as function parameters is not a good idea in my opinion.
If you do, I'd recommend wrapping them in a simple struct with a member
used to indicate which member of the union is being passed.
In my case the type is specified by an earlier argument (stripped away for
the sample program posted). Same thing, really.
X x;
x.key = Int;
x.value.i = 42;

testfunc( &x );
Right, that would work. But is not:

testfunc(Int, 42);

easier and neater? It also leaves no way for the callee to modify the
caller's variable, thus allowing better compiler optimizations...

By now I've learned from this thread, that I'm seeing a gcc-extension in
action. Why is such an extension not adopted by the C-standard remains my
question, though...

-mi
Aug 11 '06 #19

P: n/a
Mikhail Teterin <us****@aldan.algebra.comwrites:
Robert Gamble wrote:
>Perhaps you don't realize it but this is Usenet, not the BSD kernel.
Spaces are the recommended method of indentation here and for good
reason.

The reason being?..
tabs can be messed up or lost in transit. I have no idea how or why,
but it happens; someone posts this:

<TAB>{
<TAB><TAB>/* indented text */
<TAB>}

and it shows up like this:

{
/* indented text*/
}

If you're on a Unix-like system, you can filter your text through
"expand" before posting it.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 11 '06 #20

P: n/a
Mikhail Teterin <us****@aldan.algebra.comwrites:
Ian Collins wrote:
>>>>Your program appeared in my newsreader as an attachment. Please don't
post attachments here

Why? Is not a (text) attachement easier to deal with? None of the "----
cut here ---" nuissance, just save into a file and compile...
Some people use news readers that don't support attachments. On Usenet,
go for the lowest common denominator, plain text.

Come on -- that's not a valid argument. The attachements have appeared more
than 10 years ago and all news-readers (including text based ones) now
support them.
Look around this newsgroup. People post code all the time; I think
yours may have been the first non-spam attachment I've ever seen here.

Apparently not all newsreaders handle attachments sanely. They do all
handle plain text sanely.

When in Rome ...

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 11 '06 #21

P: n/a
Mikhail Teterin schrieb:
Keith Thompson wrote:
>>You can't cast to a union type in either C90 or C99. gcc apparently
provides this as an extension. This is mentioned in the "C
Extensions" section of the gcc documentation. That documentation will
also tell you about the "-ansi -pedantic" or, if you prefer, "-std=c99
-pedantic" options, which would have warned you about this.

Thanks for the most useful answer... Any ideas on why this is not part of
the C-standard (yet?)? What's wrong with this extension -- what does it
break? Yours,
There are no clear, standardized rules.
Example:
What happens for
union foo {
float bar;
long double baz;
void *qux;
int *quux;
};
if you perform
union foo Foo = 0;
As a cast is only an explicit conversion, this is the same
as
union foo Foo = (union foo) 0;

Do we get the representation of 0.0F, 0.0L, (void *)0, or (int *)0?
Note: the latter two may in theory differ.

In C99, you have compound literals to work around that (note:
compound literals look like casts but are not casts -- they
yield lvalues):

,---
#include <stdio.h>

enum which {
eWhichInvalid = -1,
eWhichFlt,
eWhichLdbl,
eWhichVPtr,
eWhichIPtr
};

union foo {
float bar;
long double baz;
void *qux;
int *quux;
};

void blib (enum which Which, union foo Foo)
{
switch (Which)
{
case eWhichFlt:
printf("%g\n", Foo.bar);
break;
case eWhichIPtr:
printf("%p\n", (void *) Foo.quux);
break;
default:
puts("Too lazy for more");
break;
}
}

int main (void)
{
blib(eWhichFlt, (union foo){.bar = 0});
blib(eWhichIPtr, (union foo){.quux = 0});
return 0;
}
`---

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 11 '06 #22

P: n/a
Keith Thompson wrote:
If you're on a Unix-like system, you can filter your text through
"expand" before posting it.
Instead I chose to post the program as an attachment, which is supposed to
allow verbatim file transfer (together with the file's type and name).

And got flamed by users of broken news-readers and their sympathizers...

Lowest common denominator indeed :-(

-mi
Aug 11 '06 #23

P: n/a
Keith Thompson wrote:
Apparently not all newsreaders handle attachments sanely. šThey do all
handle plain text sanely.
Actually, they don't -- many use proportional fonts, which is rather a
nuissance, when it comes to software code.
When in Rome ...
:-) Atilla never knew that one, I'm sure...

-mi
Aug 11 '06 #24

P: n/a
Mikhail Teterin wrote:
Keith Thompson wrote:

>>If you're on a Unix-like system, you can filter your text through
"expand" before posting it.


Instead I chose to post the program as an attachment, which is supposed to
allow verbatim file transfer (together with the file's type and name).

And got flamed by users of broken news-readers and their sympathizers...

Lowest common denominator indeed :-(
If you post here asking for advice, you follow the conventions (which
are pretty well universal across Usenet). Whether those conventions
make sense or not is moot.

--
Ian Collins.
Aug 11 '06 #25

P: n/a
Mikhail Teterin wrote:
Ian Collins wrote:

In my case the type is specified by an earlier argument (stripped away for
the sample program posted). Same thing, really.
Don't do that, it causes threads to wander off where thy wouldn't go if
you posted the correct code.
>
> X x;
x.key = Int;
x.value.i = 42;

testfunc( &x );


Right, that would work. But is not:

testfunc(Int, 42);

easier and neater? It also leaves no way for the callee to modify the
caller's variable, thus allowing better compiler optimizations...
Maybe neater in this contrived case (leaving aside the subjective
opinion on compiler optimisations), but not where the object has to be
passed though a call chain, better to encapsulate all of the pertinent
information in a single object.

Your version may appear neater, but it isn't C. if you want a cleaner
syntax, use a different language. C is explicit, you either accept it,
or use something else.

If you want the passed object to be const, declare it const.

static void testfunc( const X* x ) {...}
By now I've learned from this thread, that I'm seeing a gcc-extension in
action. Why is such an extension not adopted by the C-standard remains my
question, though...
Because it's horrible?

--
Ian Collins.
Aug 11 '06 #26

P: n/a
On Fri, 11 Aug 2006 17:56:39 -0400, Mikhail Teterin
<us****@aldan.algebra.comwrote:
>Keith Thompson wrote:
>Ugh, that's worse. In my newsreader, it shows up with a bunch of
non-printable '\232' characters.

I just saved it back to a file from the news-reader. The file is perfectly
clean, opens up fine in vi, and compiles...
Here's what I got:

typedef union {
ššššššššintššššši;
ššššššššvoidšššš*p;
ššššššššstruct {
ššššššššššššššššintššššši;
ššššššššššššššššintšššššj;
šššššššš}šššššššs;
} testunion;
>
>I don't know how they got there, but try to use only spaces for
indentation. šCopy and paste plain text if you can.

BSD's style(9) mandates use of tabs for indentation :-)
So? I didn't know BSD's style guide applied to newsgroup postings. Not
that it's much better in source code.
http://www.freebsd.org/cgi/man.cgi?q...tyle&sektion=9

Yours,

-mi
--
Al Balmer
Sun City, AZ
Aug 11 '06 #27

P: n/a
Al Balmer wrote:
Here's what I got:

typedef union {
ššššššššintššššši;
ššššššššvoidšššš*p;
ššššššššstruct {
ššššššššššššššššintššššši;
ššššššššššššššššintšššššj;
šššššššš}šššššššs;
} testunion;
Just curious, which news reader?

--
Ian Collins.
Aug 11 '06 #28

P: n/a
Ian Collins wrote:
If you post here asking for advice, you follow the conventions (which
are pretty well universal across Usenet).š
You should note, that the only two people, who provided actual advice on the
subject matter -- Keith T. and yourself -- both had no problems reading the
attachment :-)
Whether those conventions make sense or not is moot.
Which is why I started a separate thread under the subject "Posting sample
C-code as attachment" -- to discuss changing the convention. Yours,

-mi
Aug 11 '06 #29

P: n/a
Ian Collins wrote:
If you want the passed object to be const, declare it const.

static void testfunc( const X* x ) {...}
What about the caller having to know all about the union's internals?

-mi

Aug 11 '06 #30

P: n/a
Mikhail Teterin wrote:
Ian Collins wrote:

>>If you want the passed object to be const, declare it const.

static void testfunc( const X* x ) {...}


What about the caller having to know all about the union's internals?
What about it? No worse than having ton know about the type being passed.

--
Ian Collins.
Aug 11 '06 #31

P: n/a
Mikhail Teterin said:
Ian Collins wrote:
>If you post here asking for advice, you follow the conventions (which
are pretty well universal across Usenet).

You should note, that the only two people, who provided actual advice on
the subject matter -- Keith T. and yourself -- both had no problems
reading the attachment :-)
Did my second response not count as actual advice on the subject matter?
Hmm.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 11 '06 #32

P: n/a
Ian Collins said:
Al Balmer wrote:
>Here's what I got:

typedef union {
<non-printable stuff snipped>
>} testunion;
Just curious, which news reader?
According to his headers, he's using Forte Agent 3.3/32.846.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 11 '06 #33

P: n/a
Ian Collins wrote:
>>>static void testfunc( const X* x ) {...}


What about the caller having to know all about the union's internals?
What about it?šNo worse than having ton know about the type being passed.
When all I'm passing is one of the fields, I don't need to know about others
(I do currently to keep Purify happy), nor even the name of the field I'm
actually passing:

testfunc(Int, 32);

does not change, when/if the union changes...

-mi
Aug 11 '06 #34

P: n/a
Mikhail Teterin wrote:
Ian Collins wrote:

>>If you post here asking for advice, you follow the conventions (which
are pretty well universal across Usenet).


You should note, that the only two people, who provided actual advice on the
subject matter -- Keith T. and yourself -- both had no problems reading the
attachment :-)
I think you have answered your own question, others who may have helped
either couldn't read or couldn't be bothered to read your attachment.
Mozilla included it inline, so I didn't even notice there was an attachment.

--
Ian Collins.
Aug 11 '06 #35

P: n/a
Mikhail Teterin wrote:
Ian Collins wrote:

>>>>static void testfunc( const X* x ) {...}
What about the caller having to know all about the union's internals?

What about it? No worse than having ton know about the type being passed.


When all I'm passing is one of the fields, I don't need to know about others
(I do currently to keep Purify happy), nor even the name of the field I'm
actually passing:

testfunc(Int, 32);

does not change, when/if the union changes...
Again, this my be true for this simple contrived case, but not for
something more complex. Either way, you have to pass both data and
meta-data.

As you are so keen on quoting BSD stricture, have a look at the X Event
object and related code to see how this is done in a real application.

--
Ian Collins.
Aug 11 '06 #36

P: n/a
Mikhail Teterin <us****@aldan.algebra.comwrites:
Keith Thompson wrote:
>Apparently not all newsreaders handle attachments sanely. šThey do all
handle plain text sanely.

Actually, they don't -- many use proportional fonts, which is rather a
nuissance, when it comes to software code.
>When in Rome ...

:-) Atilla never knew that one, I'm sure...
So you're Atilla in this scenario? I don't think that helps your
case.

Incidentally, your followup added a '\232' character before the word
"They" in the text that you quoted (I've kept it in this followup).
You might want to find out why your newsreader, or maybe your server,
is doing this, and persuade it to stop.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 11 '06 #37

P: n/a
Mikhail Teterin wrote:
Robert Gamble wrote:
Perhaps you don't realize it but this is Usenet, not the BSD kernel.
Spaces are the recommended method of indentation here and for good
reason.

The reason being?..
The reason being that they often don't get translated as the poster
intended them to; for example, the default indentation level for tab
characters on many newsreaders is zero spaces.

Robert Gamble

Aug 11 '06 #38

P: n/a
On Fri, 11 Aug 2006 23:13:21 +0000, Richard Heathfield
<in*****@invalid.invalidwrote:
>Ian Collins said:
>Al Balmer wrote:
>>Here's what I got:

typedef union {

<non-printable stuff snipped>
>>} testunion;
Just curious, which news reader?

According to his headers, he's using Forte Agent 3.3/32.846.
Yep. I don't know whether the interpretation of whatever he sent (it
obviously wasn't spaces) was due to the reader, its configuration, or
one of the several other entities the message passed through on its
way here.

Incidentally, I ignore attachments as a matter of course. I don't even
bother to click on them to verify whether they might really be text or
not. I won't configure a reader to launch attachments automatically,
either.

--
Al Balmer
Sun City, AZ
Aug 11 '06 #39

P: n/a
On Fri, 11 Aug 2006 17:59:42 -0400, Mikhail Teterin
<us****@aldan.algebra.comwrote:
>Thanks for the most useful answer... Any ideas on why this is not part of
the C-standard (yet?)? What's wrong with this extension -- what does it
break? Yours,
If you really want to discuss this, go to comp.std.c. That's what they
do.

--
Al Balmer
Sun City, AZ
Aug 11 '06 #40

P: n/a
Keith Thompson wrote:
The program was attached to the original posting. Here it is inline.

Ugh, that's worse. In my newsreader, it shows up with a bunch of
non-printable '\232' characters.
That is 'no-break space' (&nbsp;) in the koi8-r charset.
That is probably what you get for spaces when you try to copy'n'paste
from
one of those fancy newsreaders :)
I don't know how they got there, but try to use only spaces for
indentation. Copy and paste plain text if you can.
Aug 11 '06 #41

P: n/a
On Fri, 11 Aug 2006 18:44:47 -0400, Mikhail Teterin
<us****@aldan.algebra.comwrote:
>Keith Thompson wrote:
>Apparently not all newsreaders handle attachments sanely. šThey do all
handle plain text sanely.

Actually, they don't -- many use proportional fonts, which is rather a
nuissance, when it comes to software code.
I've never seen a newsreader that couldn't be told to use a fixed
font. Care to name a couple of the many? I have seen newsreaders that
didn't provide proportional fonts (but not for a long time.)
>When in Rome ...

:-) Atilla never knew that one, I'm sure...

-mi
--
Al Balmer
Sun City, AZ
Aug 11 '06 #42

P: n/a
Richard Heathfield schrieb:
Mikhail Teterin said:
>>Ian Collins wrote:
>>>If you post here asking for advice, you follow the conventions (which
are pretty well universal across Usenet).

You should note, that the only two people, who provided actual advice on
the subject matter -- Keith T. and yourself -- both had no problems
reading the attachment :-)

Did my second response not count as actual advice on the subject matter?
Hmm.
Well, at least the OP responded to yours... ;-)

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 12 '06 #43

P: n/a
In article <14456249.nrYsuYhnoW@mishaMikhail Teterin <us****@aldan.algebra.comwrites:
Keith Thompson wrote:
Ugh, that's worse. In my newsreader, it shows up with a bunch of
non-printable '\232' characters.

I just saved it back to a file from the news-reader. The file is perfectly
clean, opens up fine in vi, and compiles...
The code \232 is apparently an additional space in the Koi-8 codes
that also implement line drawing symbols. A Cyrillic space? Not
everybody is equiped with newsreaders that understand those Koi-8
codes, and for most of them is \232 is a code that they do not
understand (it is a control code in all versions of ISO 8859, and
in standard Koi-8).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 12 '06 #44

P: n/a
In article <4390853.PoEsFBCd7e@mishaMikhail Teterin <us****@aldan.algebra.comwrites:
Robert Gamble wrote:
Perhaps you don't realize it but this is Usenet, not the BSD kernel.
Spaces are the recommended method of indentation here and for good
reason.

The reason being?..
That not everybody has the same tab settings as you.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 12 '06 #45

P: n/a
In article <4k************@individual.netMichael Mair <Mi**********@invalid.invalidwrites:
Mikhail Teterin schrieb:
....
Thanks for the most useful answer... Any ideas on why this is not part of
the C-standard (yet?)? What's wrong with this extension -- what does it
break? Yours,

There are no clear, standardized rules.
Example:
What happens for
union foo {
float bar;
long double baz;
void *qux;
int *quux;
};
if you perform
union foo Foo = 0;
As a cast is only an explicit conversion, this is the same
as
union foo Foo = (union foo) 0;

Do we get the representation of 0.0F, 0.0L, (void *)0, or (int *)0?
Note: the latter two may in theory differ.
In theory all four may differ, but I have never encountered a system
where that was the case. But I have encountered systems where the
first three were different, while the size of the first and the
third was the same. Different systems. On one, 0.0F was not all bits
0, on the other (void *)0 was not all bits 0.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 12 '06 #46

P: n/a
In article <10712129.IhiqIXrjhx@mishaMikhail Teterin <us****@aldan.algebra.comwrites:
Ian Collins wrote:
>>Your program appeared in my newsreader as an attachment. Please don't
post attachments here

Why? Is not a (text) attachement easier to deal with? None of the "----
cut here ---" nuissance, just save into a file and compile...
Some people use news readers that don't support attachments. On Usenet,
go for the lowest common denominator, plain text.

Come on -- that's not a valid argument. The attachements have appeared more
than 10 years ago and all news-readers (including text based ones) now
support them.
Well, the news-reader I am using would not recognise an attachment when you
waved it in front of its eyes. Consider, it is just piping the article
contents through "more". (Not really, but it is very similar.)
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 13 '06 #47

P: n/a
In article <2d********************************@4ax.comal****************@att.net writes:
On Fri, 11 Aug 2006 18:44:47 -0400, Mikhail Teterin
<us****@aldan.algebra.comwrote:
Keith Thompson wrote:
Apparently not all newsreaders handle attachments sanely. šThey do all
handle plain text sanely.
Actually, they don't -- many use proportional fonts, which is rather a
nuissance, when it comes to software code.
I've never seen a newsreader that couldn't be told to use a fixed
font. Care to name a couple of the many? I have seen newsreaders that
didn't provide proportional fonts (but not for a long time.)
My newsreader is using the font that the window is using where it displays
the articles. In this case just the window of a telnet session, but I
could have told the telnet session to use a proportional font.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 13 '06 #48

P: n/a
In article <ln************@nuthaus.mib.orgKeith Thompson <ks***@mib.orgwrites:
Mikhail Teterin <us****@aldan.algebra.comwrites:
Keith Thompson wrote:
Apparently not all newsreaders handle attachments sanely. šThey do all
handle plain text sanely.
....
Incidentally, your followup added a '\232' character before the word
"They" in the text that you quoted (I've kept it in this followup).
You might want to find out why your newsreader, or maybe your server,
is doing this, and persuade it to stop.
Nope, he is just using a space that is present in the Koi-8 encoding,
instead of the standard space.
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 13 '06 #49

P: n/a
Dik T. Winter schrieb:
In article <4k************@individual.netMichael Mair <Mi**********@invalid.invalidwrites:
Mikhail Teterin schrieb:
...
Thanks for the most useful answer... Any ideas on why this is not part of
the C-standard (yet?)? What's wrong with this extension -- what does it
break? Yours,
>
There are no clear, standardized rules.
Example:
What happens for
union foo {
float bar;
long double baz;
void *qux;
int *quux;
};
if you perform
union foo Foo = 0;
As a cast is only an explicit conversion, this is the same
as
union foo Foo = (union foo) 0;
>
Do we get the representation of 0.0F, 0.0L, (void *)0, or (int *)0?
Note: the latter two may in theory differ.

In theory all four may differ,
Argh -- of course I meant that the first three are more likely to
differ... *sigh*
Thank you for making that clearer.
but I have never encountered a system
where that was the case. But I have encountered systems where the
first three were different, while the size of the first and the
third was the same. Different systems. On one, 0.0F was not all bits
0, on the other (void *)0 was not all bits 0.
The former, 0.0F not being all bits zero, I have also encountered.
Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 13 '06 #50

50 Replies

This discussion thread is closed

Replies have been disabled for this discussion.