Coding conventions amendment

Dear rolling IoTlers,

as far I'm concerned it has been an undocumented coding convention so far to use `int` or `unsigned int` for iterator variables in a loop instead of fixed width integer types. Does anybody object to adding this to the coding conventions explicitly?

Cheers, Oleg

Hi,

Hi,

Hi,

Dear rolling IoTlers,

as far I'm concerned it has been an undocumented coding convention so far to use `int` or `unsigned int` for iterator variables in a loop instead of fixed width integer types. Does anybody object to adding this to the coding conventions explicitly?

What about `size_t`?

+1 for size_t

Cheers, Ludwig

_______________________________________________ devel mailing list devel@riot-os.org https://lists.riot-os.org/mailman/listinfo/devel

Best regards, Martin

Hi!

Hi,

`size_t` is optimal for every architecture that does not use segmented memory.

The only platform that I know which used segmented memory was 80286, which was not produced since the mid 90th. According to Wikipedia the last architecture that used segmented memory died out in 1997.

So, +1 for size_t from me, too.

Cheer René

Hi,

size_t is suited best to be used for iterating array indices and never overflow holding them [1]. [1] Best regards, Martin

Hi Martin!

Hi,

size_t is the type returned from sizeof() call that you may use to determine any object size (including length of static arrays), so for my understanding the returned size_t value can not exceed the highest possible index for any array that can be allocated on the underlying platform. But as Kaspar suggested we should probably state against using fixed width and only recommend size_t.

+1 for size_t

Hi,

Does anybody object to adding this to the coding >> conventions explicitly?

> What about `size_t`?

+1 for size_t

Well, any convention would need careful wording.

for (uint32_t timeout = 1; timeout < (10LU*1000*1000); timeout *= 2) {
	if(try()) break;
}

... cannot blindly by convention converted to size_t as loop variable.

IMHO this example also answers Oleg's initial concern: sometimes int or unsigned int or size_t just don't work.

Kaspar

Kaspar,

Hi,

Does anybody object to adding this to the coding

conventions explicitly?

What about `size_t`?

+1 for size_t

Well, any convention would need careful wording.

for (uint32_t timeout = 1; timeout < (10LU*1000*1000); timeout *= 2) {
	if(try()) break;
}

... cannot blindly by convention converted to size_t as loop variable.

Of course not. But I believe the question was more, in case of an unsigned type, should we use "unsigned int" or size_t. In that case I would go for size_t.

IMHO this example also answers Oleg's initial concern: sometimes int or unsigned int or size_t just don't work.

Sure.

Hi,

Hi,

Hi Ludwig!

Hi Kees!

I agree with the general idea of this thread.

In my opinion, integer widths should only be specified in cases where the developer needs to know the exact width, for example in network protocols or when interfacing with hardware. In normal program logic the variables should be using the general types, such as int, long, double, or size_t. This goes for code in general, not just iterator variables.

Best regards, Joakim

OK. In that case I wouldn't recommend anything.

Hi,