Author Topic: Is there a error with long double sizeof ?  (Read 2978 times)

Offline 2Eric

  • Multiple posting newcomer
  • *
  • Posts: 10
Is there a error with long double sizeof ?
« on: September 08, 2024, 01:22:16 am »
The book says 10 bytes the program below says 8 bytes


#include <iostream>

using namespace std;

int main()
{
    cout << "The size of bool   is:\t" << sizeof(bool) << " bytes.\n";  //1
    cout << "The size of char   is:\t" << sizeof(char) << " bytes.\n";   //1
    cout << "The size of short  is:\t" << sizeof(short) << " bytes.\n";  //2
    cout << "The size of int    is:\t" << sizeof(int) << " bytes.\n";    //4
    cout << "The size of float  is:\t" << sizeof(float) << " bytes.\n";  //4
    cout << "The size of long   is:\t" << sizeof(long) << " bytes.\n";   //4
    cout << "The size of double is:\t" << sizeof(double) << " bytes.\n";  //8
    cout << "\n";

   cout << "The size of unsigned short int is:\t" << sizeof(unsigned short int) << " bytes.\n"; //2
   cout << "The size of unsigned long int is:\t" << sizeof(unsigned long int) << " bytes.\n"; //2
   cout << "The size of long int  is:\t\t" << sizeof(long int) << " bytes.\n"; //4
    cout << "The size of wchar_t is:\t\t\t" << sizeof(wchar_t) << " bytes.\n"; //2
    cout << "The size of unsigned int is:\t\t" << sizeof(unsigned int) << " bytes.\n"; //4
    cout << "The size of long double is:\t\t" << sizeof(long double) << " bytes.\n"; //8
    return 0;
}

Offline fredIcn

  • Single posting newcomer
  • *
  • Posts: 3
Re: Is there a error with long double sizeof ?
« Reply #1 on: September 08, 2024, 01:17:55 pm »
Perhaps the 10 bytes is related to the fact that functions like printf() and scanf() use the default Microsoft Visual C++ Runtime (MSVCR) library functions, which allow only 64-bit floating points, while MinGW uses its own 80-bit implementation.
Keep in mind that results depend on the platform. CodeBlocks/GCC on 32-bit Windows computers shows 12 bytes as the result, and 64-bit Windows shows 16 bytes for long double. See attached screenshot and https://stackoverflow.com/questions/4089174/printf-and-long-double. I hope this helps
« Last Edit: September 10, 2024, 06:53:56 pm by fredIcn »

Offline Miguel Gimenez

  • Developer
  • Lives here!
  • *****
  • Posts: 1632
Re: Is there a error with long double sizeof ?
« Reply #2 on: September 08, 2024, 01:39:08 pm »
This is OT here, please use C++ forums for this kind of questions.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7665
    • My Best Post
Re: Is there a error with long double sizeof ?
« Reply #3 on: September 08, 2024, 04:29:27 pm »
Link to help you know what is On Topic instead of Off Topic (OT) https://forums.codeblocks.org/index.php/topic,9996.0.html
Link to FAQs https://wiki.codeblocks.org/index.php/FAQ

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline 2Eric

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Is there a error with long double sizeof ?
« Reply #4 on: September 08, 2024, 06:40:34 pm »
This is OT here, please use C++ forums for this kind of questions.
I do not believe this, WHERE has someone said I tried the program you listed on my computer and it works good. with 10 bytes , 

Offline 2Eric

  • Multiple posting newcomer
  • *
  • Posts: 10
Re: Is there a error with long double sizeof ?
« Reply #5 on: September 08, 2024, 07:05:46 pm »
This is OT here, please use C++ forums for this kind of questions.
I do not believe this, WHERE has someone said I tried the program you listed on my computer and it works good. with 10 bytes , 

Maybe about 24 hours ago ago I spend a few minutes looking for a link to donate money to the project, I could not find it, maybe I should ask my bank where the link is.
I went to bed last thinking I am getting some value out of Code::Block, I was really looking forward to making a donation. BUT the replied I am getting now, I am going to wipe Code::Blocks off the system and try out come other C++ program, and if I get banned from this group that will be one sure way that some other C++ project gets some donation from me.         
 

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7665
    • My Best Post
Re: Is there a error with long double sizeof ?
« Reply #6 on: September 08, 2024, 09:45:07 pm »
This is OT here, please use C++ forums for this kind of questions.
I do not believe this, WHERE has someone said I tried the program you listed on my computer and it works good. with 10 bytes , 

Maybe about 24 hours ago ago I spend a few minutes looking for a link to donate money to the project, I could not find it, maybe I should ask my bank where the link is.
I went to bed last thinking I am getting some value out of Code::Block, I was really looking forward to making a donation. BUT the replied I am getting now, I am going to wipe Code::Blocks off the system and try out come other C++ program, and if I get banned from this group that will be one sure way that some other C++ project gets some donation from me.         
 

Suggest looking up the term "Help Vampire" because I think you will likely be labeled one in the future.
Read this website rules and the FAQs I posted if you wish to continue on this website!

Tim S.
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org

Offline Wkerry

  • Multiple posting newcomer
  • *
  • Posts: 54
Re: Is there a error with long double sizeof ?
« Reply #7 on: September 11, 2024, 11:14:27 am »
@2Eric seems like you do not know what the difference between an IDE and a compiler is. I would suggest you have a read on what an IDE is and what a compiler is to find out the difference.

You are complaining about the compiler you are using, but blaming the IDE that has NOTHING to to with your problem.

The issue you raise should be closed as it has nothing to do with Codeblocks IDE.