www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - 64-bit D and interfacing with C

reply David Friedman <dvdfrdmn users.ess-eff.net> writes:
Many of the Phobos modules that interface C currently use 'int' and 
'uint' when the actual C declaration is 'long' or 'unsigned long'.  This 
works 32-bit sytems, but not for most 64-bit sytems.

Should there be a standard definition for the C long and unsigned long 
types? My current solution is to add 'Clong_t' and 'Culong_t' to the 
std.stdint module:

     version(GNU)
     {
	import gcc.builtins;
	alias __builtin_Clong Clong_t;
	alias __builtin_Culong Culong_t;
     }
     else /* For DMD: */ version(X86_64)
     {
	// Needs more conditionals for LP64 vs. LLP64...
	alias long Clong_t;
	alias ulong Culong_t;
     }
     else
     {
	alias int Clong_t;
	alias uint Culong_t;
     }
Feb 18 2007
next sibling parent Sean Kelly <sean f4.ca> writes:
David Friedman wrote:
 Many of the Phobos modules that interface C currently use 'int' and 
 'uint' when the actual C declaration is 'long' or 'unsigned long'.  This 
 works 32-bit sytems, but not for most 64-bit sytems.
 
 Should there be a standard definition for the C long and unsigned long 
 types? My current solution is to add 'Clong_t' and 'Culong_t' to the 
 std.stdint module:
 
     version(GNU)
     {
     import gcc.builtins;
     alias __builtin_Clong Clong_t;
     alias __builtin_Culong Culong_t;
     }
     else /* For DMD: */ version(X86_64)
     {
     // Needs more conditionals for LP64 vs. LLP64...
     alias long Clong_t;
     alias ulong Culong_t;
     }
     else
     {
     alias int Clong_t;
     alias uint Culong_t;
     }

For what it's worth, Tango has a module called tango.stdc.config which defines the symbols c_long and c_ulong. stdint sounds like a good place for these decls if an existing module is preferred. Sean
Feb 18 2007
prev sibling parent Gregor Richards <Richards codu.org> writes:
David Friedman wrote:
 Many of the Phobos modules that interface C currently use 'int' and 
 'uint' when the actual C declaration is 'long' or 'unsigned long'.  This 
 works 32-bit sytems, but not for most 64-bit sytems.
 
 Should there be a standard definition for the C long and unsigned long 
 types? My current solution is to add 'Clong_t' and 'Culong_t' to the 
 std.stdint module:
 
     version(GNU)
     {
     import gcc.builtins;
     alias __builtin_Clong Clong_t;
     alias __builtin_Culong Culong_t;
     }
     else /* For DMD: */ version(X86_64)
     {
     // Needs more conditionals for LP64 vs. LLP64...
     alias long Clong_t;
     alias ulong Culong_t;
     }
     else
     {
     alias int Clong_t;
     alias uint Culong_t;
     }

I was arguing for this to make bcd.gen more robust, but everybody shot it down ... not with any good excuse, just because they're jerks :) - Gregor Richards
Feb 18 2007