unsigned policy
renoX
renosky at free.fr
Wed Feb 7 12:11:03 PST 2007
Henning Hasemann a écrit :
> I know this is a more general questions as it applies to C and C++ as well,
> but somewhere I have to ask and actually D is what Im coding in:
>
> Should one try to use uint in favor of int whenever one knows for sure the value
> wont be negative? That whould be a bit more expressive but on the other hand
> sometimes leads to type problems.
> For example, when having things like this:
>
> T min(T)(T a, T b) {
> return a < b ? a : b;
> }
>
> Here you whould need to ensure to cast values so they share a common type.
>
> How do you code? Do you use uint whenever it suitable reflects the data to
> store (eg a x-y-position on the screen) or only when necessary?
I don't know the generic answer, but for an x-y position, using unsigned
would be a bad idea: if you had a rectangle only partially visible on
the screen for example, you wouldn't be able to represent it.
Regards,
renoX
>
> TIA for your tips,
> Henning
More information about the Digitalmars-d
mailing list