User forums > General (but related to Code::Blocks)

Is there a error with long double sizeof ?

(1/2) > >>

2Eric:
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;
}

fredIcn:
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

Miguel Gimenez:
This is OT here, please use C++ forums for this kind of questions.

stahta01:
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.

2Eric:

--- Quote from: Miguel Gimenez on September 08, 2024, 01:39:08 pm ---This is OT here, please use C++ forums for this kind of questions.

--- End quote ---
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 , 

Navigation

[0] Message Index

[#] Next page

Go to full version