[elektro] Nahh, ujabb C problema

Moczik Gabor pm_levlista at progzmaster.hu
Wed Sep 9 21:48:08 CEST 2009


Hali!

Ez a kod szerintetek legalis?

--------------
#include <stdio.h>

struct prot_config_t {
     unsigned short checksum;
     union {
         #pragma pack(1)
         struct config_t {
             unsigned char  a;
             unsigned char  b;
             long long      x64;
         } /* id1 */;
         unsigned char   raw[sizeof(struct config_t)];
     } /* id2 */;
};

#define CONF_SIZE  sizeof(struct config_t)

struct prot_config_t   conf;

void main(void)
{
     unsigned char i;

     conf.a = 0x11;
     conf.b = 0x22;
     conf.x64 = 0x123456789ABCDEF;
     for(i=0; i<CONF_SIZE; i++) {
         printf("%02X ",conf.raw[i]);
     }
}
---------------------

TCC-vel lefordul es jol mukodik
SDCC-vel lefordul, bizonyara mukodik,
HT PICC18 nem viszi, az 'id1' es 'id2' nelkul "no identifier in declaration" 
van. Ha benne van, akkor utana 'conf.a = 0x11' jellegu sornal "not a member 
of struct/union" hiba van, 'conf.id1.a' es tarsai sem fordul le.

Mellesleg az id1, id2 hatasara mar a masik ket forditoval sem jo.

Amint sejtheto, az lenne a lenyeg, hogy a config_t -re tudjak checksum-ot 
szamolni a conf.raw[] segitsegevel.

-- 
((( Móczik Gábor  )))--((( E~mail: "pm-01" @AT "progzmaster" .DOT "hu" )))
((( Skype: moczik )))



More information about the Elektro mailing list