Jump to content
  • Advertisement
Sign in to follow this  
dawidjoubert

Is this Size Deduction correct

This topic is 4892 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Quote:
Original post by Endar
Quote:
Original post by JohnBSmall
Unless you're on a very unusual system, 'char' will be one byte....


What kind of unusual systems have 'char' as not a byte? Some of the older ones?


In managed languages as C# a char is 2 bytes. UNICODE forced down your throat.

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by JohnBSmall
Quote:
Original post by SiCrane
None. char is defined to be one byte.

Odd... I wonder why they didn't just call it 'byte' then.

John B


Backwards compatibility with C.

Back in C days, people did a lot of bad stuff with regards to text handling (in particular, assuming it's ok to represent each character of a string in one byte, and then put a special byte at the end and set a pointer to the beginning) - 'char' and 'byte' became synonymous. In C++, sizeof(char) == 1, i.e. the char size is defined to be one byte, but a byte is *not* guaranteed to be 8 bits (it is, however, guaranteed to be *at least* that much, and also that memory consists of contiguous bytes with no holes in between) - to unambiguously refer to 8 bits in technical discussion, use 'octet'.

Share this post


Link to post
Share on other sites
Quote:
Original post by Zahlman
Quote:
Original post by JohnBSmall
Quote:
Original post by SiCrane
None. char is defined to be one byte.

Odd... I wonder why they didn't just call it 'byte' then.

John B

Backwards compatibility with C.

No, I meant why was 'char' chosen when it was actually a choice (presumably when C was designed, although maybe even in an earlier language).

John B

Share this post


Link to post
Share on other sites
Quote:
Original post by Puzzler183
It's not defined as a byte. I don't have a copy of the standard, but it's not.


Quote:
The 2003 C++ standard - 5.3.3 sizeof
The sizeof operator yields the number of bytes in the object representation of its operand. The operand
is either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall not
be applied to an expression that has function or incomplete type, or to an enumeration type before all its
enumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designates
a bit-field. sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1;


So sizeof gives the number of bytes. And sizeof(char), sizeof(signed char) and sizeof(unsigned char) are 1, which means they are 1 byte.

Share this post


Link to post
Share on other sites
Original post by Dave
This:

struct var
{
int a;
float pos[12];
float tex[8];
float n[3];
char bytes[2];
bool passable;
};

and then just

size_t size = sizeof(var);
printf("%d",(int)size);

And than you have it, MAN! where do you live?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!