Menu

Long = 4 bytes

2003-01-06
2012-09-26
  • Nobody/Anonymous

    hi when i'm compiling with dev cpp long is being allocated only 4 bytes isnt it supposed to allocate 8???

    Im a newbie so please bear me....

     
    • Nobody/Anonymous

      I did a quick check in my book, long is required to be at least 4 bytes, and at least as big as int.  It does not have to be bigger.

      In some cases, you can use long long, though I don't remember if that works under gcc, I remember running into some display issues.

      I also remember being smarter than I am too.

      Wayne

       
    • Nobody/Anonymous

      if you can ?, use a double if need be.
      check your computer
      #include <iostream>
           using namespace std;

      int main( )
        {
        cout << sizeof(double) << endl;
           system("PAUSE");
          return 0;
        }

       
    • Nobody/Anonymous

      I guess I was presuming that they wanted an integer type, which may have been a false presumption on my part...

      Modifying the code you so graciously provided in the service of answering my question about long long:

      #include <iostream>
      using namespace std;

      int main( )
      {
      cout << sizeof(double) << endl;
      cout << sizeof(int) << endl;
      cout << sizeof(long) << endl;
      cout << sizeof(long long) << endl;
      system("PAUSE");
      return 0;
      }

      I find that long long does in fact show up as 8 bytes.   I still remember some funnies in getting it displayed or used.  He said, scratching his head...

      Wayne

      Wayne

       
    • Nobody/Anonymous

      in my experience:

      char=1=BYTE
      int=2=WORD
      long=4=DWORD
      double=8

      -yano

       
    • Patrick Ogay

      Patrick Ogay - 2003-01-06

      ctypes: http://www.sysprog.net/ctype.html

      A "word" is dependent on CPU-achitecture and compiler-implementation.
      I read in R. Stevens "Network Programming" about some reliable length of datatypes: it's not so evident that an int is 16 or 32 bit.
      (I think a short is 16, a long is 32 and a int is machine depended...)

      Many libraries (particularly network) provide datatyes like int32,  to be certain about the length. 
      Patrick

       
    • Anonymous

      Anonymous - 2003-01-06

      In a 32bit environment/compiler, long is normally 32bits (however it need not be so, simply at least 32bits, and at least as large as int - ANSI C specification).

      You can use sizeof() to portably deternine the size of any type, class, struct, array, or instance of any of these.

      Also <limits> (or <limits.h> in C) defines macros specifying the min and max values that may be represented by the basic types.

      gcc does support long long (at least it does in the ARM cross-compiler version I also use). However, using long long may affect portability.

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.