# 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.

## Recommended Posts

Quote:
Original post by Endar
Quote:
 Original post by JohnBSmallUnless 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 on other sites
Quote:
 Original post by SiCraneNone. char is defined to be one byte.

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

John B

##### Share on other sites
Quote:
Original post by JohnBSmall
Quote:
 Original post by SiCraneNone. 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 on other sites
Quote:
Original post by Zahlman
Quote:
Original post by JohnBSmall
Quote:
 Original post by SiCraneNone. 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 on other sites
It's not defined as a byte. I don't have a copy of the standard, but it's not.

##### Share on other sites
Quote:
 Original post by Puzzler183It'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 sizeofThe sizeof operator yields the number of bytes in the object representation of its operand. The operandis either an expression, which is not evaluated, or a parenthesized type-id. The sizeof operator shall notbe applied to an expression that has function or incomplete type, or to an enumeration type before all itsenumerators have been declared, or to the parenthesized name of such types, or to an lvalue that designatesa 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 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?

• 17
• 9
• 15
• 60