Hi again,
I tried the solution provided by mattd earlier but I get an error (As shown in the text below). I have created a simple project (as shown in the source box below).
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\TestProject.o ..\src\TestProject.cpp
..\src\TestProject.cpp:47: error: use of enum `iOpStartLights' without previous declaration
..\src\TestProject.cpp:47: error: expected unqualified-id before '{' token
..\src\TestProject.cpp: In function `int main()':
..\src\TestProject.cpp:63: error: `iOpStartLights' was not declared in this scope
..\src\TestProject.cpp:63: warning: unused variable 'iOpStartLights'
Build error occurred, build is stopped
Time consumed: 297 ms.
#include <iostream>using namespace std;#ifdef _MSC_VER#define COMPILER_MSVC#endif#ifdef __GNUC__#define COMPILER_GCC#endif#ifdef _WIN32#define PLATFORM_WINDOWS#endif#ifdef _WIN64#define PLATFORM_WINDOWS#endif#ifndef PLATFORM_WINDOWS#define PLATFORM_LINUX#endif#if defined(COMPILER_MSVC)#define PACKED_ENUM(e) enum e : unsigned char#elif defined(COMPILER_GCC)#define PACKED_ENUM(e) enum __attribute__((__packed__)) e#else// Fallback - don't use packed enums#define PACKED_ENUM(e) enum e#endifPACKED_ENUM(iOpStartLights){ STARTLIGHT_NOTSET = 0, STARTLIGHT_CONFIG_0 = 1, STARTLIGHT_CONFIG_1 = 2, STARTLIGHT_CONFIG_2 = 3, STARTLIGHT_CONFIG_3 = 4, STARTLIGHT_CONFIG_4 = 5, STARTLIGHT_CONFIG_5 = 6, STARTLIGHT_CONFIG_6 = 7, STARTLIGHT_CONFIG_7 = 8, STARTLIGHT_RESET_CONFIG = 20, STARTLIGHT_FORCE_START = 21, STARTLIGHT_MAX,};int main() { cout << sizeof(iOpStartLights) << endl; cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!! return 0;}
When i try to define (see below) it gives an error:
enum __attribute__((__packed__)) myEnumOld{ NUMBER1 = 0, NUMBER2 = 1, NUMBER3 = 2,};
Errors:
..\src\TestProject.cpp:13: error: use of enum `myEnumOld' without previous declaration
..\src\TestProject.cpp:13: error: expected unqualified-id before '{' token
When I define it as (see below) it all works oke:
enum myEnum{ NUMBER1 = 0, NUMBER2 = 1, NUMBER3 = 2,}__attribute__((__packed__));
Any ideas on why it does this ?
@Ozak
I know it's hell for the moment (especially because it needs to stay compatible with Visual Studio). I also have 2 installs off gcc (first one on ubuntu version 4.something second on windows version 3.4.5 (which is even worse).
With Kind Regards,
EyeSize
[Edited by - EyeSize on February 17, 2010 4:27:18 AM]