Wednesday, March 7, 2018

[389-devel] Use of int types in the code base,

Hi there,

http://www.port389.org/docs/389ds/development/coding-style.html#types

In a few reviews I still see this sometimes.

It's pretty important that we keep moving our quality standard higher,
and having known type sizes is important to this. Types like int and
long are unknown sizes until you compile it depending on platform.

As a result, it's really important we use the intX_t and uintX_t types
so we have guarantees of our values. I would encourage the use of
int64_t and uint64_t, because while they are "larger", it's
significantly faster for a modern 64bit system to process these values
than their 32bit counterparts.

Another note is that arrays index by size_t, not 'int', so we should
always keep this in mind.

Finally, because we are using c99 now, this means we should avoid:

size_t i = 0;

for (i = 0; i < cond; i++) {
...
}

When we really should scope our values. Scoping is good because it
limits possibility of data corruption to flow and other mistakes such
as re-use of values. This means:

for (size_t i = 0; i < cond; i++) {
...
}

Thanks!

--
Thanks,

William Brown
_______________________________________________
389-devel mailing list -- 389-devel@lists.fedoraproject.org
To unsubscribe send an email to 389-devel-leave@lists.fedoraproject.org

No comments:

Post a Comment