|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
I'm writing some cross-platform code and I invite the developer to pick their own integer types in places. However, the integer type must be unsigned. So far, I make sure this is so with: typedef int SegIMustBeUnsigned[(SegI)-1 > 0 ? 3 : -3]; Yes, this does the trick, but I'm just wondering if anyone here has a better way of doing it. -- Tomás Ó hÉilidhe |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
Tomás Ó hÉilidhe <t...@lavabit.com> wrote:
> I'm writing some cross-platform code and I invite the > developer to pick their own integer types in places. > However, the integer type must be unsigned. BTW, be careful about allowing unsigned types that promote to (signed) int. > So far, I make sure this is so with: > > typedef int SegIMustBeUnsigned[(SegI)-1 > 0 ? 3 : -3]; > > Yes, this does the trick, but I'm just wondering if > anyone here has a better way of doing it. Google for compile time asserts. There are a few ways, but none of them are any more or less elegant that what you have. -- Peter |
|
![]() |
| Outils de la discussion | |
|
|