Author Topic: hinting to anonymous union do not work?  (Read 7099 times)

rabidus

  • Guest
hinting to anonymous union do not work?
« on: June 09, 2005, 06:11:45 pm »
Hello,

Is hinting to anonymous union work?

something like this:
>>>>>>> BLOCK START <<<<<<<<<<
struct RGB{
   float r,g,b;
};
struct HLS{
   float h,l,s;
}
struct Pixel{
   union{
      struct RGB rgb;
      struct HLS hls;
   };
} my_pixel;
>>>>>>> BLOCK END <<<<<<<<<<
 
and hinting do not work if I write:
my_pixel.rgb.??????

Offline David Perfors

  • Developer
  • Lives here!
  • *****
  • Posts: 560
hinting to anonymous union do not work?
« Reply #1 on: June 09, 2005, 06:54:57 pm »
after struct Pixel you mis ";" (without quotes)
OS: winXP
Compiler: mingw
IDE: Code::Blocks SVN WX: 2.8.4 Wish list: faster code completion, easier debugging, refactoring

eques.m

  • Guest
hinting to anonymous union do not work?
« Reply #2 on: June 10, 2005, 07:37:09 pm »
No, i have not missed enything. Code is compilable properly, and work as it should. If here is any mistake, it was made during post writing.

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
hinting to anonymous union do not work?
« Reply #3 on: June 11, 2005, 07:24:38 pm »
Quote from: mispunt
after struct Pixel you mis ";" (without quotes)

A valid point  ;)
If your code does not miss that semicolon, it compiles without problems and works perfectly on gcc 3.4.2 MingW as well as gcc 3.4.3 FC3 -- tried both.

Depending on which compiler you use, you may get different results, however, and in particular, you may get different results when compiling C and C++.
ISO C++ does not allow anonymous structs, some compilers respect that, some others don't (and some do in only certain versions!).
In this case, when upgrading compiler you may suddenly face your code to stop compiling when it would before, so the best way is probably to not use anonymous structs at all.

gcc 3.x accepts this construct for backwards-compatibility:
http://gcc.gnu.org/onlinedocs/gcc-3.4.4/gcc/Unnamed-Fields.html#Unnamed-Fields
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."