Jump to content
  • Advertisement
Sign in to follow this  
jordi_0071

sizeof() more then just 1?

This topic is 4816 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

hey, this piece of code: aChar = sizeof (char); will print a smiley and is character 1, but can i print for example character 2 with sizeof? if its possible then how?

Share this post


Link to post
Share on other sites
Advertisement
Wait.... what? Why are you doing this thing?

If you want to set aChar to 1, set it to 1. There's no need to use sizeof() here. It's not at all what sizeof() is used for.

Share this post


Link to post
Share on other sites
With sizeof() you can determine how big something is in terms of chars.

For instance if sizeof(int) returns 4, then an int takes up the same space as 4 chars would.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Quote:
Original post by jordi_0071
but where is sizeof() needed for anyway?


It's from C which uses malloc/free for dynamic memory allocation and void * for generics. C++ uses new/delete and templates, which can infer the size, for the same purposes.

Share this post


Link to post
Share on other sites
Quote:
Original post by nmi
With sizeof() you can determine how big something is in terms of chars.

For instance if sizeof(int) returns 4, then an int takes up the same space as 4 chars would.


sizeof(int) is equal to 4 on your compiler. sizeof(int) can be theoretically anything.

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Quote:
Original post by nmi
With sizeof() you can determine how big something is in terms of chars.

For instance if sizeof(int) returns 4, then an int takes up the same space as 4 chars would.


sizeof(int) is equal to 4 on your compiler. sizeof(int) can be theoretically anything.

Which is probably why the sentence started with 'For instance if'.

John B

Share this post


Link to post
Share on other sites
jordi_0071, what are you trying to do? I mean in a very general sense. What is the goal of your program, or that part of your program? We can help you out, but I am 100% that the answer does not involve sizeof.

Not only do beginners often not know the answers, they don't even know what questions to ask. So when you come for help say "I'm trying to do this, I tried it this way and it doesn't work, what should I do?"

Share this post


Link to post
Share on other sites
Quote:
Original post by SiCrane
Quote:
Original post by nmi
With sizeof() you can determine how big something is in terms of chars.

For instance if sizeof(int) returns 4, then an int takes up the same space as 4 chars would.


sizeof(int) is equal to 4 on your compiler. sizeof(int) can be theoretically anything.


That's what I said, since it was just an example.
For 16 Bit systems, size(int) may return 2 as well.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!