Jump to page: 1 25  
Page
Thread overview
enum scope
Jan 26, 2012
Trass3r
Jan 26, 2012
Jonathan M Davis
Jan 26, 2012
bcs
Jan 26, 2012
Michel Fortin
Jan 26, 2012
Trass3r
Jan 26, 2012
Mike Parker
Jan 27, 2012
Daniel Murphy
Jan 28, 2012
Andrej Mitrovic
Jan 28, 2012
Andrej Mitrovic
Jan 28, 2012
Andrej Mitrovic
Jan 28, 2012
Daniel Murphy
Jan 28, 2012
Andrej Mitrovic
Jan 28, 2012
Daniel Murphy
Jan 28, 2012
Trass3r
Jan 28, 2012
Andrej Mitrovic
Jan 28, 2012
Trass3r
Jan 28, 2012
Andrej Mitrovic
Jan 28, 2012
Jonathan M Davis
Jan 28, 2012
Trass3r
Jan 28, 2012
Mike Wey
Jun 07, 2014
Walter Bright
Jun 07, 2014
deadalnix
Jun 08, 2014
Jacob Carlborg
Jun 08, 2014
Walter Bright
Jun 08, 2014
Jacob Carlborg
Jun 08, 2014
Walter Bright
Jun 09, 2014
Jacob Carlborg
Jun 08, 2014
Walter Bright
Jun 08, 2014
Jacob Carlborg
Jun 09, 2014
Mike Parker
Jan 26, 2012
Jacob Carlborg
Jan 26, 2012
Trass3r
Jan 26, 2012
Michel Fortin
Jan 26, 2012
Trass3r
Jan 26, 2012
Jacob Carlborg
Jan 26, 2012
Trass3r
Jan 26, 2012
Jacob Carlborg
Jan 26, 2012
Gor Gyolchanyan
Jan 26, 2012
Timon Gehr
Jan 26, 2012
Timon Gehr
Jan 26, 2012
Trass3r
Jan 26, 2012
Mike Parker
Jan 26, 2012
Trass3r
Jun 07, 2014
Meta
Jun 07, 2014
Trass3r
January 26, 2012
When writing C bindings I usually create lots of aliases via a string mixin to pull enum members into the enclosing scope so it's compatible to C.
Would it be wise to let the compiler do this automatically for extern(C) enums?
January 26, 2012
On Thursday, January 26, 2012 02:06:45 Trass3r wrote:
> When writing C bindings I usually create lots of aliases via a
> string mixin to pull enum members into the enclosing scope so
> it's compatible to C.
> Would it be wise to let the compiler do this automatically for
> extern(C) enums?

Why? You're using them in D code, not C code. What difference does it make if the enum is one that's used in C code or not? Why would you use such aliases with enums from C but not those from D/ What makes enums from C different?

- Jonathan M Davis
January 26, 2012
On 01/25/2012 05:12 PM, Jonathan M Davis wrote:
> On Thursday, January 26, 2012 02:06:45 Trass3r wrote:
>> When writing C bindings I usually create lots of aliases via a
>> string mixin to pull enum members into the enclosing scope so
>> it's compatible to C.
>> Would it be wise to let the compiler do this automatically for
>> extern(C) enums?
>
> Why? You're using them in D code, not C code. What difference does it make if
> the enum is one that's used in C code or not? Why would you use such aliases
> with enums from C but not those from D/ What makes enums from C different?
>
> - Jonathan M Davis

Copy paste portability?
January 26, 2012
On 2012-01-26 02:06, Trass3r wrote:
> When writing C bindings I usually create lots of aliases via a string
> mixin to pull enum members into the enclosing scope so it's compatible
> to C.
> Would it be wise to let the compiler do this automatically for extern(C)
> enums?

You can use anonymous enums. The members will then live in the global scope. You can then use just one alias to an int, uint or what's appropriate.

-- 
/Jacob Carlborg
January 26, 2012
> You can use anonymous enums. The members will then live in the global scope. You can then use just one alias to an int, uint or what's appropriate.

Yeah but you loose type safety.
January 26, 2012
On 2012-01-26 01:12:40 +0000, Jonathan M Davis <jmdavisProg@gmx.com> said:

> On Thursday, January 26, 2012 02:06:45 Trass3r wrote:
>> When writing C bindings I usually create lots of aliases via a
>> string mixin to pull enum members into the enclosing scope so
>> it's compatible to C.
>> Would it be wise to let the compiler do this automatically for
>> extern(C) enums?
> 
> Why? You're using them in D code, not C code. What difference does it make if
> the enum is one that's used in C code or not? Why would you use such aliases
> with enums from C but not those from D/ What makes enums from C different?

Often C enum value naming takes into account that they'll live in the outer scope. For instance:

	enum UITableViewRowAnimation {
   	UITableViewRowAnimationFade,
	    UITableViewRowAnimationRight,
	    UITableViewRowAnimationLeft,
	    UITableViewRowAnimationTop,
	    UITableViewRowAnimationBottom,
	    UITableViewRowAnimationNone,
	    UITableViewRowAnimationMiddle,
	    UITableViewRowAnimationAutomatic = 100
	}

So if you're doing direct bindings where you don't want to change the names, how do you use that in D?

	UITableViewRowAnimation.UITableViewRowAnimationFade

-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

January 26, 2012
On 2012-01-26 11:51:10 +0000, "Trass3r" <un@known.com> said:

>> You can use anonymous enums. The members will then live in the global scope. You can then use just one alias to an int, uint or what's appropriate.
> 
> Yeah but you loose type safety.

Or if you absolutely need both type safety and the values to live in the outer scope, you can do this:

	enum Something
	{
		SomethingPointy,
		SomethingSmooth,
	}
	alias Something.SomethingPointy SomethingPointy;
	alias Something.SomethingSmooth SomethingSmooth;

But that's rather extreme verbosity at the definition.


-- 
Michel Fortin
michel.fortin@michelf.com
http://michelf.com/

January 26, 2012
> Or if you absolutely need both type safety and the values to live in the outer scope, you can do this:
>
> 	enum Something
> 	{
> 		SomethingPointy,
> 		SomethingSmooth,
> 	}
> 	alias Something.SomethingPointy SomethingPointy;
> 	alias Something.SomethingSmooth SomethingSmooth;
>
> But that's rather extreme verbosity at the definition.

As I said in the first post, this is what I actually do.
Though I use a mixin like mixin(bringIntoCurrentScope!Something);

But inserting this everywhere is rather annoying. And since the whole module is guarded by an extern(C): anyway I figured the compiler could do it for me.
January 26, 2012
> Often C enum value naming takes into account that they'll live in the outer scope. For instance:
>
> 	enum UITableViewRowAnimation {
>   	UITableViewRowAnimationFade,
> 	    UITableViewRowAnimationRight,
> 	    UITableViewRowAnimationLeft,
> 	    UITableViewRowAnimationTop,
> 	    UITableViewRowAnimationBottom,
> 	    UITableViewRowAnimationNone,
> 	    UITableViewRowAnimationMiddle,
> 	    UITableViewRowAnimationAutomatic = 100
> 	}
>
> So if you're doing direct bindings where you don't want to change the names, how do you use that in D?
>
> 	UITableViewRowAnimation.UITableViewRowAnimationFade

Precisely.
See dmd's source code, enum STC {STCscope, STCforeach, ...}, enum MOD {MODconst, MODshared,...}, etc.
January 26, 2012
On 2012-01-26 12:51, Trass3r wrote:
>> You can use anonymous enums. The members will then live in the global
>> scope. You can then use just one alias to an int, uint or what's
>> appropriate.
>
> Yeah but you loose type safety.

It's not type safe in C. But you can wrap it in a struct with alias this instead.

-- 
/Jacob Carlborg
« First   ‹ Prev
1 2 3 4 5