Re: [hackers] [quark] Use sizeof() instead of magic constants || FRIGN
I got an example:
try compiling this code:
#include <stdio.h>
int
main(void)
{
printf("%d", sizeof unsigned char);
return (0);
}
you will probably get a compiler error like this:
sizeof.c: In function ‘main’:
sizeof.c:6:22: error: expected expression before ‘unsigned’
printf("%d", sizeof unsigned char);
^~~~~~~~
However, with parenthesies:
#include <stdio.h>
int
main(void)
{
printf("%d\n", sizeof(unsigned char));
return (0);
}
It will compile successfully.
Hope you got the idea
Raiz
On 2016-09-05 10:25, FRIGN wrote:
> On Mon, 5 Sep 2016 07:42:36 +0200
> Anselm R Garbe <garbeam_AT_gmail.com> wrote:
>
> Hey Anselm,
>
>> Quick note: your syntax usage of sizeof is not 100% accurate.
>>
>> Use 'sizeof(type)' with brackets but 'sizeof var' without.
>
> I use sizeof always function-like and see no reason why I shouldn't use
> "sizeof(var)" and instead use "sizeof var". It doesn't alter the code
> behaviour and ultimately it's all about readability.
> If you eyes have become accustomed to always use function-like syntax
> for such operators the best bet is not to break this style because it's
> not "necessary" to have parentheses for variable sizeof's.
>
> Cheers
>
> FRIGN
Received on Mon Sep 05 2016 - 09:34:49 CEST
This archive was generated by hypermail 2.3.0
: Mon Sep 05 2016 - 09:36:21 CEST