public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/16330] New: Unions handled incorrectly with -fshort-enums
@ 2004-07-02 16:38 miko at stacken dot kth dot se
2004-07-02 16:50 ` [Bug c/16330] " pinskia at gcc dot gnu dot org
` (3 more replies)
0 siblings, 4 replies; 5+ messages in thread
From: miko at stacken dot kth dot se @ 2004-07-02 16:38 UTC (permalink / raw)
To: gcc-bugs
The following code correctly prints 1 when compiled without -fshort-enums, but
incorrectly prints a 0 when compiled with -fshort-enums. I assume this is an
endian problem as it works correctly on a i686-pc-linux-gnu target.
#include <stdio.h>
enum E { a, b };
union Y
{
int x;
enum E y;
void* z;
};
int main()
{
union Y un;
un.x=1;
printf("%d\n", un.y);
}
--
Summary: Unions handled incorrectly with -fshort-enums
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: miko at stacken dot kth dot se
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: sparc-sun-solaris
GCC host triplet: sparc-sun-solaris
GCC target triplet: sparc-sun-solaris
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16330
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/16330] Unions handled incorrectly with -fshort-enums
2004-07-02 16:38 [Bug c/16330] New: Unions handled incorrectly with -fshort-enums miko at stacken dot kth dot se
@ 2004-07-02 16:50 ` pinskia at gcc dot gnu dot org
2004-07-02 17:02 ` miko at stacken dot kth dot se
` (2 subsequent siblings)
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-02 16:50 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-07-02 16:50 -------
Not a bug, the code (with -fshort-enum) is equivent to:
#include <stdio.h>
enum E { a, b };
union Y
{
int x;
short y;
void* z;
};
int main()
{
union Y un;
un.x=1;
printf("%d\n", un.y);
}
Again this is not a bug.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16330
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/16330] Unions handled incorrectly with -fshort-enums
2004-07-02 16:38 [Bug c/16330] New: Unions handled incorrectly with -fshort-enums miko at stacken dot kth dot se
2004-07-02 16:50 ` [Bug c/16330] " pinskia at gcc dot gnu dot org
@ 2004-07-02 17:02 ` miko at stacken dot kth dot se
2004-07-02 17:18 ` pinskia at gcc dot gnu dot org
2004-07-02 17:37 ` miko at stacken dot kth dot se
3 siblings, 0 replies; 5+ messages in thread
From: miko at stacken dot kth dot se @ 2004-07-02 17:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From miko at stacken dot kth dot se 2004-07-02 17:02 -------
You're going to have to explain this one to me.
1) It works as expected on other platforms
2) If I use char or short, I get 0 in both cases. At least this is consistent,
even though it's surely wrong? But by using an enum, which under -fshort-enums
should be resolved to a char, not a short (single byte is the smallest that can
contain all of the values, and is how large gcc allocates in a struct) it
produces two different values???
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16330
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/16330] Unions handled incorrectly with -fshort-enums
2004-07-02 16:38 [Bug c/16330] New: Unions handled incorrectly with -fshort-enums miko at stacken dot kth dot se
2004-07-02 16:50 ` [Bug c/16330] " pinskia at gcc dot gnu dot org
2004-07-02 17:02 ` miko at stacken dot kth dot se
@ 2004-07-02 17:18 ` pinskia at gcc dot gnu dot org
2004-07-02 17:37 ` miko at stacken dot kth dot se
3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-07-02 17:18 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-07-02 17:18 -------
Basically it is because of endian differences, read a good book about endian to
get the full explaination.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16330
^ permalink raw reply [flat|nested] 5+ messages in thread
* [Bug c/16330] Unions handled incorrectly with -fshort-enums
2004-07-02 16:38 [Bug c/16330] New: Unions handled incorrectly with -fshort-enums miko at stacken dot kth dot se
` (2 preceding siblings ...)
2004-07-02 17:18 ` pinskia at gcc dot gnu dot org
@ 2004-07-02 17:37 ` miko at stacken dot kth dot se
3 siblings, 0 replies; 5+ messages in thread
From: miko at stacken dot kth dot se @ 2004-07-02 17:37 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From miko at stacken dot kth dot se 2004-07-02 17:37 -------
I understand endian differences. For some reason I assumed the compiler would
take care of that for me, by storing the enum in [offset+3] rather than in
[offset+0]. One of the downsides to porting I suppose...
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=16330
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2004-07-02 17:37 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-07-02 16:38 [Bug c/16330] New: Unions handled incorrectly with -fshort-enums miko at stacken dot kth dot se
2004-07-02 16:50 ` [Bug c/16330] " pinskia at gcc dot gnu dot org
2004-07-02 17:02 ` miko at stacken dot kth dot se
2004-07-02 17:18 ` pinskia at gcc dot gnu dot org
2004-07-02 17:37 ` miko at stacken dot kth dot se
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).