+ 9

The schedule shows the sizeof int as 2 bytes while it should be 4 ....

correction

13th Feb 2018, 8:25 PM
Abdulhamid KAYAL
Abdulhamid KAYAL - avatar
14 Respostas
+ 8
char is guaranteed 1 byte. short, long, and long long are guaranteed at least 2, 4, 8 bytes. int is guaranteed at least 2 bytes but is usually implemented as 4 bytes. Use int8_t, int16_t, int32_t and int64_t if you need guaranteed width. Correction: apparently char isn't guaranteed either. Edit: I am finding conflicting information about wether or not char is guaranteed as 1 byte so if anyone has an answer that'd be great. However, it doesn't matter because you won't find an implementation with anything else anyway.
13th Feb 2018, 8:47 PM
Vlad Serbu
Vlad Serbu - avatar
+ 6
deae Jamie , dear Vlad, I thank both of you for your detailed answers and support, İt is really kind of you
13th Feb 2018, 8:51 PM
Abdulhamid KAYAL
Abdulhamid KAYAL - avatar
+ 4
yes, exactly , C++ here in SL
13th Feb 2018, 8:46 PM
Abdulhamid KAYAL
Abdulhamid KAYAL - avatar
+ 3
@Ankit there are different compilers and each compiler works differently. some goes from left to right and while other goes from right to left . so to see that just run the code. pre is earlier there performing operation. post after the operation . hope you get the result
18th Feb 2018, 4:41 PM
Prakhar Agarwal
Prakhar Agarwal - avatar
+ 2
I see , is it the same for the other types? thank you so much
13th Feb 2018, 8:34 PM
Abdulhamid KAYAL
Abdulhamid KAYAL - avatar
+ 2
@Vlad Serbu: char is definitely 1 byte Unicode uses 2 bytes (wchar) to circumvent the ASCII limits (256 unsigned: 0-255). When working with a raw file/buffer, it doesn't matter unless you need to interpret the data. @OP: int is a very generic type that assumes the size the compiler gives it. This was to help C be portable back in the day. SL are using a virtual machine and compiler AFAIK. Use the fixed-width types as suggested. The reason for SL's decision is likely reducing memory use.
13th Feb 2018, 11:54 PM
non
+ 2
on different compilers the value of int is different. but mostly it is 4 bytes on most of the platform
18th Feb 2018, 5:07 AM
Prakhar Agarwal
Prakhar Agarwal - avatar
+ 1
Well Martin's test clarifies it all. Perhaps an error in OP's code? Unless changes made during an update (unlikely). OP, just try running your code again. I also tried and get 4 bytes for int.
14th Feb 2018, 11:48 PM
non