Struct vs Classes?

Started by
30 comments, last by jbadams 11 years, 5 months ago

Listen to KaiserJohan. He knows what he's talking about, however, he defined a 32BPP pixel incorrectly with alpha last in rightmost byte (0xAABBCC*DD*). It should be like this:

#define byte unsigned char

typedef struct {
byte a, r, g, b;
} PIXEL;

That is nothing but a matter of convention.
RGBA formats are just as common as ARGB. There is no right or wrong way to do it (though it is a good idea to stick with the convention used by your rendering API—that is ARGB on Direct3D and RGBA on OpenGL/OpenGL ES).
You are the same person who said C++ is for newbies, yet you yourself seem to be quite a beginner. Stop saying things as matter-of-factual when you yourself have misunderstood what the facts are.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Advertisement

Structs have constructors and destructors aswell.. they get 'random' values if you dont define them (i.e the compiler generates them), which is exactly the same for a class.


That wording is extremely misleading. The compiler doesn't "generate" anything. It would be insanely stupid to write a compiler that spends all the effort of filling uninitialized variables with random content instead of a clearly defined value like 0. Those values are random, because the existing memory content isn't touched (so technically it isn't even random). The most important exception are debug builds, if the compiler is nice to enough to fill them with (very much not random) patterns to help you track down bugs like uninitialized variables or freeing/deleting something twice.
f@dzhttp://festini.device-zero.de

he defined a 32BPP pixel incorrectly

That's not incorrect, it's simply a different convention, and as L.Spiro says neither is really more common than the other.


Like some of the others, I would personally recommend a beginner not learn asm until they have a firm handle on programming concepts in general. It is useful to know what your code converts to, and I think most experienced programmers would benefit from such knowledge, but to a beginner trying to learn about those topics is more likely to just be confusing and might encourage an unhealthy pre-occupation with attempting to hand-optimise unnecessarily.

- Jason Astle-Adams

This topic is closed to new replies.

Advertisement