Click here to Skip to main content
15,895,370 members

Nested and unnamed unions and structures do not compile in gcc-4.6.

nicetuxedo asked:

Open original thread
The code compiles under gcc 4.4 with the following command

gcc -fms-extensions experiment.c

Under gcc 4.6 I get errors

#include <stdio.h>

typedef unsigned char          uint8_t;
typedef unsigned short         uint16_t;

typedef signed char            sint8_t;
typedef signed short           sint16_t;

/*
** Decomposition of 16 bis
** in 8 bits
*/
typedef union raw_16_bits_entry
{
   uint16_t raw;
   sint16_t sraw;
   uint8_t  byte[2];

   /* H/L byte access */
   struct
   {
      uint8_t blow;
      uint8_t bhigh;

   } __attribute__((packed));

} __attribute__((packed)) raw16_t;

typedef union raw_msr_entry
{
   struct
   {
      uint8_t  eax;
      uint8_t  edx;

   } __attribute__((packed));

   raw16_t;

} __attribute__((packed)) msr_t;



typedef union amd_syscfg_msr
{
   struct
   {
      uint16_t   rsv0:4;
      uint16_t   mfde:1;
      uint16_t   mfdm:1;
      uint16_t   mvdm:1;
      uint16_t   tom2:1;

   } __attribute__((packed));

   msr_t;
   raw16_t;

} __attribute__((packed)) amd_syscfg_msr_t;

int main()
{

    amd_syscfg_msr_t q;
    q.rsv0=5;
    q.raw=7;
    printf("hello world!");
};



Under gcc 4.6 I get errors with -fms-extensions
exp1.c:15:13: error: duplicate member ‘raw’
exp1.c:16:13: error: duplicate member ‘sraw’
exp1.c:17:13: error: duplicate member ‘byte’
exp1.c:22:15: error: duplicate member ‘blow’
exp1.c:23:15: error: duplicate member ‘bhigh’
exp1.c: In function ‘main’:
exp1.c:66:6: error: ‘amd_syscfg_msr_t’ has no member named ‘raw’


without -fms-extensions
exp1.c:38:11: warning: declaration does not declare anything [enabled by default]
exp1.c:56:9: warning: declaration does not declare anything [enabled by default]
exp1.c:57:11: warning: declaration does not declare anything [enabled by default]
exp1.c: In function ‘main’:
exp1.c:66:6: error: ‘amd_syscfg_msr_t’ has no member named ‘raw’


I can not find any compiler options that will help.
Tags: C, GCC, Compilation

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900