BeanBrain 0 Posted April 21, 2006 Report Share Posted April 21, 2006 Bug description: Anonymous reference with union / structure generates error - should it? Steps to reproduce: Compile the example code as is, it will generate errors. If you uncomment the #define BOOSTC line it will compile OK because the unions / structure are no longer anonymous nor are the accesses to them. // BoostC Compiler options -v -W2 -t PIC18F4550 #include <system.h> typedef unsigned char b_ytes; typedef unsigned int word; // uncomment next line to compile successfully //#define BOOSTC typedef union _BYTE { b_ytes _byte; struct { #ifdef BOOSTC b_ytes bits; } anony0; #else b_ytes bits; }; #endif } BYTE; typedef union _WORD { word _word; struct { b_ytes byte0; b_ytes byte1; #ifdef BOOSTC } anony1; #else }; #endif struct { BYTE Byte0; BYTE Byte1; #ifdef BOOSTC } anony2; #else }; #endif struct { BYTE LowB; BYTE HighB; #ifdef BOOSTC } anony3; #else }; #endif struct { b_ytes v[2]; #ifdef BOOSTC } anony4; #else }; #endif } WORD; WORD W1; WORD W2; unsigned int i1=123; unsigned int i2=456; b_ytes b0='a'; b_ytes b1='z'; //------------------------------------------------------ void main() { #ifdef BOOSTC W1._word=i1; W2.anony1.byte0=b0; W2.anony1.byte1=b1; W2=W1; W2.anony2.Byte0._byte=b0; W2.anony3.HighB.anony0.bits=0xaa; #else W1._word=i1; W2.byte0=b0; W2.byte1=b1; W2=W1; W2.Byte0._byte=b0; W2.HighB.bits=0xaa; #endif } // END Expected behaviour: To compile the example with #define BOOSTC commented out. Is the problem 100% reproduceable: Yes IDE version: SourceBoost IDE version 6.35 Compiler: BoostC Compiler Compiler version: 6.35 Target device: PIC18F4550 OS: : XP Pro SP2 Comments: Anonymous references make for prettier code - if you could implement it would be nice, perhaps with a compiler switch to enable if necessary Quote Link to post Share on other sites
Pavel 0 Posted April 21, 2006 Report Share Posted April 21, 2006 The code you submitted is a bit difficult to read. The general rule is that the simplier the code is the sooner the problem gets fixed. Regards, Pavel Quote Link to post Share on other sites
BeanBrain 0 Posted April 22, 2006 Author Report Share Posted April 22, 2006 The code you submitted is a bit difficult to read. The general rule is that the simplier the code is the sooner the problem gets fixed. Regards, Pavel <{POST_SNAPBACK}> Hi Pavel, Sorry about the lack of easy reading, but it was necessary in ordet to demonstrate and to test the error. Regards, G Quote Link to post Share on other sites
Pavel 0 Posted April 23, 2006 Report Share Posted April 23, 2006 The code you submitted is a bit difficult to read. The general rule is that the simplier the code is the sooner the problem gets fixed. Regards, Pavel <{POST_SNAPBACK}> Hi Pavel, Sorry about the lack of easy reading, but it was necessary in ordet to demonstrate and to test the error. I looked at the code and found out that I didn't even know that such constructions are allowed in C That's why compiler doesn't support this feature. Will add this work into my todo list but can't promise it will be implemented soon. Regards, Pavel Quote Link to post Share on other sites
Dave 0 Posted April 23, 2006 Report Share Posted April 23, 2006 BeanBrain, I thought anonymous structures within a union was a microsoft specific extention to the language. I ported some code from MSVC++ to GCC G++ and had to name all my anonymous unions. Regards Dave Quote Link to post Share on other sites
DL1968 0 Posted April 23, 2006 Report Share Posted April 23, 2006 (edited) I thought anonymous structures within a union was a microsoft specific extention to the language. I ported some code from MSVC++ to GCC G++ and had to name all my anonymous unions. IIRC, Microchip's C18 supports them. That's elegant to read and saves some keystrokes, but can easily confuse lint and other static analysis tools. EDIT: I confirm that MPLAB C18 supports unnamed structures within a union. That's explicitly stated on page 17 of their document DS51288A "MPLAB C18 C Compiler User's Guide" (and I do have on my HD some serial protocol handling code that makes use of this feature, as well). As regards C'99, section 6.7.8 (regarding initialization) of the draft generically mentions "unnamed members of objects of type structure and union" as well. Edited April 23, 2006 by DL1968 Quote Link to post Share on other sites
Recommended Posts
Join the conversation
You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.