Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C compilation GCC
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.
Posted 12-Jan-12 14:00pm

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You need to give names to all union members.
In your code, the sub-unions have no name -> no declaration warning.
With the extension, the anonymous sub-unions seem to introduce their members directly into the current union. This results in having the members raw, etc. declared twice.
Your composition of unions maps the first union twice, which looks a bit odd...
 
Give a name to all members, and all is C-language conformant.
 
Cheers
Andi
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



Advertise | Privacy | Mobile
Web04 | 2.8.141022.2 | Last Updated 13 Jan 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100