We are currently migrating Bugzilla to GitHub issues.
Any changes made to the bug tracker now will be lost, so please do not post new bugs or make changes to them.
When we're done, all bug URLs will redirect to their equivalent location on the new bug tracker.

Bug 4377

Summary: SDL_PIXELFORMAT enum is anonymous, which prevents its use in a templated function
Product: SDL Reporter: zen3d <danm>
Component: *don't know*Assignee: Ryan C. Gordon <icculus>
Status: RESOLVED FIXED QA Contact: Sam Lantinga <slouken>
Severity: normal    
Priority: P2    
Version: 2.0.9   
Hardware: x86_64   
OS: Linux   

Description zen3d 2018-11-11 02:12:24 UTC
While trying to build Pixie lisp (https://github.com/pixie-lang/pixie), which uses SDL for multimedia output, the mandelbrot example won't build. The problem is that internally pixie uses a templated function to dump a value, and gcc chokes because SDL_PIXELFORMAT_RGA8888 is an anonymous enum.

I solved the problem locally by changing from:
   enum {
      SDL_PIXELFORMAT_UNKNOWN,
      ... etc. ...
      SDL_PIXELFORMAT_YUYV = ... etc ...
   };
to:
   typedef enum {
      SDL_PIXELFORMAT_UNKNOWN,
      ... etc. ...
      SDL_PIXELFORMAT_YUYV = ... etc ...
   } SDL_PIXELFORMAT_ENUM;
The net result of this change is that the enum containing SDL_PIXELFORMAT_* is no longer an anonymous enum and can now be used by a templated function.

This local change fixes Pixie lisp for me.

I did notice that you use the idiom 
   typedef enum {
      ... etc ...
   } SDL_FOO;
elsewhere in your code, so that change to SDL_PIXELFORMAT doesn't look like it would have a negative impact.

However, I'm not familiar enough with your code base or with the clients of that code base to know with any level of confidence if this is a valid change within your broader context.

That said, it appears that you have a number of anonymous enums scattered throughout your headers, and it seems to me that fixing those as well would be desirable to make SDL just a little bit more universal.
Comment 1 Sam Lantinga 2018-11-13 00:47:32 UTC
Yes, all the enums in the public headers are intended to be typedef'd. If you've already found them, can you provide a patch to fix this?

Thanks!
Comment 2 zen3d 2018-11-13 02:30:49 UTC
I can't say that I have a definitive list of files, since the only one I looked at was SDL_pixels.h, since that was the only one that impacted what I was doing.

However, there are several anonymous enums in SDL_pixels.h (but not a lot; maybe 5 or 6).

On the other hand, I am not familiar with your coding conventions nor have I set up a build environment for SDL. For the handful of anonymous enums in SDL_pixels.h, it would be just as easy for you to find them and validate correctness of the subsequent build than for me to do it.

Sorry. But thanks for considering this issue.
Comment 3 Sam Lantinga 2018-11-13 03:24:12 UTC
Oh, I see what's happening here. The pixel format enum is not intended to be an exhaustive list of pixel formats, so it's an unnamed enumeration of composed values.

Your change makes sense, and I'm checking that in. Please let me know if there are other cases where this is a problem.

https://hg.libsdl.org/SDL/rev/b590d04d5cf7

Thanks!
Comment 4 zen3d 2018-11-13 05:58:55 UTC
Thanks, that should address my immediate issue.

However, it is not hard to imagine that exercising utilization of other enums by pixie lisp (or elsewhere) might provoke further instances of this issue. But this is a good start.

I can probably create more failure instances if that is of interest to you.
Comment 5 Sam Lantinga 2018-11-13 16:02:22 UTC
I reviewed the anonymous unions, and they are that way in general because the values are intended to be used as integer values not limited by a fixed enumerated set. You're welcome to provide real world cases where this causes problems, but please don't contrive cases if they're not affecting anyone.