www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - size of C enum

reply Trevor Parscal <trevorparscal hotmail.com> writes:
I am still working on FreeType for D, and I am having trouble, of course.

Sooo, if FreeType is in C, and I am writing a binding... And there is an 
enum in the headers, which is refered to by the name of the enumeration...

I should take this...

/* C Code */
typedef enum FT_Glyph_Format_
{
	FT_GLYPH_FORMAT_NONE = 0,
	FT_GLYPH_FORMAT_COMPOSITE = 1668246896,
	FT_GLYPH_FORMAT_BITMAP = 1651078259,
	FT_GLYPH_FORMAT_OUTLINE = 1869968492,
	FT_GLYPH_FORMAT_PLOTTER = 1886154612
} FT_Glyph_Format;
/* */

and write this?

/* D Code */
alias int FT_Glyph_Format;
const int FT_GLYPH_FORMAT_NONE = 0;
const int FT_GLYPH_FORMAT_COMPOSITE = 1668246896;
const int FT_GLYPH_FORMAT_BITMAP = 1651078259;
const int FT_GLYPH_FORMAT_OUTLINE = 1869968492;
const int FT_GLYPH_FORMAT_PLOTTER = 1886154612;
/* */

The reason I am asking, is because I am getting an error that the 
FT_Glyph_Format is invalid, which to me hints wrong data type, but I 
have tried everything I feel like...

How big is a C enumeration in D? Am I doing this all wrong? ANY Help 
would be really great!

-- 
Thanks,
Trevor Parscal
www.trevorparscal.com
trevorparscal hotmail.com
Jun 27 2005
parent reply "Unknown W. Brackets" <unknown simplemachines.org> writes:
I would personally just do this:

enum FT_Glyph_Format
{
     FT_GLYPH_FORMAT_NONE = 0,
     FT_GLYPH_FORMAT_COMPOSITE = 1668246896,
     FT_GLYPH_FORMAT_BITMAP = 1651078259,
     FT_GLYPH_FORMAT_OUTLINE = 1869968492,
     FT_GLYPH_FORMAT_PLOTTER = 1886154612
}

But you could do this:

alias int FT_Glyph_Format;
const FT_Glyph_Format FT_GLYPH_FORMAT_NONE = 0;
const FT_Glyph_Format FT_GLYPH_FORMAT_COMPOSITE = 1668246896;
const FT_Glyph_Format FT_GLYPH_FORMAT_BITMAP = 1651078259;
const FT_Glyph_Format FT_GLYPH_FORMAT_OUTLINE = 1869968492;
const FT_Glyph_Format FT_GLYPH_FORMAT_PLOTTER = 1886154612;

An enum will be, afaik, an int by default.

-[Unknown]


 I am still working on FreeType for D, and I am having trouble, of course.
 
 Sooo, if FreeType is in C, and I am writing a binding... And there is an 
 enum in the headers, which is refered to by the name of the enumeration...
 
 I should take this...
 
 /* C Code */
 typedef enum FT_Glyph_Format_
 {
     FT_GLYPH_FORMAT_NONE = 0,
     FT_GLYPH_FORMAT_COMPOSITE = 1668246896,
     FT_GLYPH_FORMAT_BITMAP = 1651078259,
     FT_GLYPH_FORMAT_OUTLINE = 1869968492,
     FT_GLYPH_FORMAT_PLOTTER = 1886154612
 } FT_Glyph_Format;
 /* */
 
 and write this?
 
 /* D Code */
 alias int FT_Glyph_Format;
 const int FT_GLYPH_FORMAT_NONE = 0;
 const int FT_GLYPH_FORMAT_COMPOSITE = 1668246896;
 const int FT_GLYPH_FORMAT_BITMAP = 1651078259;
 const int FT_GLYPH_FORMAT_OUTLINE = 1869968492;
 const int FT_GLYPH_FORMAT_PLOTTER = 1886154612;
 /* */
 
 The reason I am asking, is because I am getting an error that the 
 FT_Glyph_Format is invalid, which to me hints wrong data type, but I 
 have tried everything I feel like...
 
 How big is a C enumeration in D? Am I doing this all wrong? ANY Help 
 would be really great!
 

Jun 27 2005
parent Stewart Gordon <smjg_1998 yahoo.com> writes:
Unknown W. Brackets wrote:
 I would personally just do this:
 
 enum FT_Glyph_Format
 {
     FT_GLYPH_FORMAT_NONE = 0,
     FT_GLYPH_FORMAT_COMPOSITE = 1668246896,
     FT_GLYPH_FORMAT_BITMAP = 1651078259,
     FT_GLYPH_FORMAT_OUTLINE = 1869968492,
     FT_GLYPH_FORMAT_PLOTTER = 1886154612
 }
 
 But you could do this:
 
 alias int FT_Glyph_Format;
 const FT_Glyph_Format FT_GLYPH_FORMAT_NONE = 0;
 const FT_Glyph_Format FT_GLYPH_FORMAT_COMPOSITE = 1668246896;
 const FT_Glyph_Format FT_GLYPH_FORMAT_BITMAP = 1651078259;
 const FT_Glyph_Format FT_GLYPH_FORMAT_OUTLINE = 1869968492;
 const FT_Glyph_Format FT_GLYPH_FORMAT_PLOTTER = 1886154612;
 
 An enum will be, afaik, an int by default.

How about this? enum FT_Glyph_Format { NONE = 0, COMPOSITE = 1668246896, BITMAP = 1651078259, OUTLINE = 1869968492, PLOTTER = 1886154612 } No point forcing yourself to write such redundancies as FT_Glyph_Format.FT_GLYPH_FORMAT_COMPOSITE all the time. This way, the final underscore effectively turns into a dot. This is how, in SDWF, I create enums from Windows API constants. Stewart. -- My e-mail is valid but not my primary mailbox. Please keep replies on the 'group where everyone may benefit.
Jul 01 2005