POD type sizes on a 64bit processor

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jeyshree
    New Member
    • Jul 2010
    • 75

    POD type sizes on a 64bit processor

    thank u sir donbock,
    actually i wished to know whem memory would be allocated for global variables in c compiler?and i got a reply that it would be allocated before main execution starts.
    sir now i have another doubt ?my processor is intel(r) core(tm) 2 duo cpu E7500 @2.93GHz.what will be the size of pointer variable in c in my computer? will it vary on on some other microprocessor like 16 and 32 bit processor.i think mine is 64 bit processor
  • Dheeraj Joshi
    Recognized Expert Top Contributor
    • Jul 2009
    • 1129

    #2
    Use sizeof() to know about this.

    Regards
    Dheeraj Joshi

    Comment

    • jeyshree
      New Member
      • Jul 2010
      • 75

      #3
      answer regarding

      Sir,
      I actually dont have c in my computer.now i am actually running my progreams in my sister's computer which is actually a 32 bit processor.So please give me the answer.

      Comment

      • donbock
        Recognized Expert Top Contributor
        • Mar 2008
        • 2427

        #4
        Why does this matter?

        I'm not just being grumpy. It sounds like you're trying to do something that depends on a particular size for a pointer variable. Hopefully we can find a more portable way to proceed.

        Comment

        • jeyshree
          New Member
          • Jul 2010
          • 75

          #5
          doubt in pointers in c

          hello,
          can someone please explain me the size of int,char,float, double,long int ,short int ,int *,float *,char *,double * and other pointers in 64 bit processor? my computer is a 32 bit processor so i am asking u.thanks in advance.

          Comment

          • donbock
            Recognized Expert Top Contributor
            • Mar 2008
            • 2427

            #6
            My initial response is "Why do you want to know?"
            The vast majority of programs can be written without any concern for the size of the types.

            The answer to your question is ... it depends. Type sizes vary from one platform to another. That's a very good reason to try to write programs that don't depend on the types being a certain size.

            You can ask your compiler to tell you the sizes if you really need to know:
            Code:
            printf("The size of int is %d\n", sizeof(int));
            ...
            printf("The size of double* is %d\n", sizeof(double*));

            Comment

            • Dheeraj Joshi
              Recognized Expert Top Contributor
              • Jul 2009
              • 1129

              #7
              I already suggested you to use sizeof().

              Regards
              Dheeraj Joshi.

              By the way, what are you trying to achieve?

              Comment

              • Banfa
                Recognized Expert Expert
                • Feb 2006
                • 9067

                #8
                Read this

                and next time try a little searching for yourself.

                Comment

                • jeyshree
                  New Member
                  • Jul 2010
                  • 75

                  #9
                  Originally posted by dheerajjoshim
                  I already suggested you to use sizeof().

                  Regards
                  Dheeraj Joshi.

                  By the way, what are you trying to achieve?
                  hello,
                  i came to know that size of int ,char and other data types as well as pointers will vary in 16,32,64 bit processor.i just want to know the size of different data types in 32 and 64 bit processor.and i also wish to know why they change?

                  Comment

                  • Banfa
                    Recognized Expert Expert
                    • Feb 2006
                    • 9067

                    #10
                    They change because different processors have different size registers, i.e. it is a physical property of the processor.

                    Some processors, notably the 64bit ones used in PCs today are equally happy using 32bit or 64bit values so then it becomes a property of how the operating system was compiled (in 32 or 64 bit mode)

                    Comment

                    • donbock
                      Recognized Expert Top Contributor
                      • Mar 2008
                      • 2427

                      #11
                      This is not just a matter of 32-bit versus 64-bit processors. You should assume that the type sizes might change every time you move
                      • from one version of a compiler to another version of the same compiler;
                      • from one compiler vendor to another;
                      • from one target environment to another.

                      You ought to be able to write software that is not affected by such changes.

                      It worries me when somebody is so interested in the type sizes -- I worry that you want to write software that will only work for one set of type sizes.

                      You can count on the following rules being true for all compilers and target environments:
                      • sizeof(char) is defined as 1.
                      • sizeof(short) <= sizeof(int).
                      • sizeof(int) <= sizeof(long).
                      • sizeof(long) <= sizeof(long long).
                      • char is at least 8 bits wide.
                      • short is at least 16 bits wide.
                      • int is at least 16 bits wide.
                      • long is at least 32 bits wide.
                      • long long is at least 64 bits wide.

                      Comment

                      Working...