How do i declare a byte variable?

F

Frederick Gotham

Martijn van Buul posted:
Utter nonsense. There are plenty of reasons and plenty of applications
where you *do* want to use a char if possible, and where it would even
be *faster*.


Show me where a char is faster than an int.

Furthermore, given that a char is slower than an int, show me why you would
want to use one for storing an integer (or than creating massive arrays).

*most* systems? Nonsense. Only on systems with a severe alignment
problem.


"char" doesn't have alignment requirements.

1) Those systems, should they exist, are rare.


Don't a lot of Intel chips work like that? 486? Pentium?

2) It would only be "efficient" from a minimum-execution-time point of
view.


Yes indeed, it would be quicker.

It's grossly inefficient regarding memory usage.


Three bytes is a drop in the ocean.

An easy test for this is the following:

#include <stdio.h>

int main(void)
{
struct FourBytes { char a,b,c,d; };

switch(sizeof(struct FourBytes))
{
case sizeof(char[4]):
puts("Packed nice and tight!");
break;

This "proves" nor disproves absolutely nothing.


It proves that the char's haven't been placed directly after each other in
memory. Guess why.

Nonsense. Again.


Perform arithmetic or equality on it and see what happens.

My stance is this: Never use char unless memory is scarce.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top