Thread: size_t

  1. #1
    Registered User
    Join Date
    Sep 2014
    Posts
    16

    size_t

    I think that compilers use different types for defining size_t (and other defined types in C standard library) according to the environment bit depth.

    So, for example, if I write a code for a 32-bit computer, size_t can be unsigned int, but if I write a code for a 64-bit computer, then size_t can be unsigned long ...it is so?

    Do compilers define the type of size_t automatically according to the chosen type of projects?

  2. #2
    Registered User MutantJohn's Avatar
    Join Date
    Feb 2013
    Posts
    2,665
    This may be of interest : The GNU C Library: Important Data Types

  3. #3
    Unregistered User Yarin's Avatar
    Join Date
    Jul 2007
    Posts
    2,158
    Quote Originally Posted by KemalT View Post
    it is so?
    Yes.


    Quote Originally Posted by KemalT View Post
    Do compilers define the type of size_t automatically according to the chosen type of projects?
    Compliers don't know what a "project" is, you're probably thinking of an IDE. But either way, yes, compliers and IDEs usually compile to the platform you're compling on.

  4. #4
    Registered User
    Join Date
    May 2010
    Posts
    4,498
    So, for example, if I write a code for a 32-bit computer, size_t can be unsigned int, but if I write a code for a 64-bit computer, then size_t can be unsigned long ...it is so?
    The size_t is implementation defined type so yes different compilers can and do define this using different undefined types. By the way it is not necessarily related to the number of "bits" of the computer. For example a 32bit compiler could define the size_t as an unsigned long if it so desired.

    And remember all the integral types have implementation defined maximums. The standard only says that the maximums must be at least so large. For example an int must be able to hold values of at least 32767.

    Jim

  5. #5
    Registered User
    Join Date
    Sep 2014
    Posts
    16
    Thanks a lot to all ...

    Quote Originally Posted by Yarin View Post
    Compliers don't know what a "project" is, you're probably thinking of an IDE. But either way, yes, compliers and IDEs usually compile to the platform you're compling on.
    Then, I think that there are two or more related header files for those type definitons and the compiler uses the appropriate one for intended computer architecture when compiling the code ... right?
    Last edited by KemalT; 02-09-2015 at 12:35 PM.

  6. #6
    Registered User
    Join Date
    Oct 2006
    Posts
    3,445
    Quote Originally Posted by KemalT View Post
    So, for example, if I write a code for a 32-bit computer, size_t can be unsigned int, but if I write a code for a 64-bit computer, then size_t can be unsigned long ...it is so?
    With Visual C++, even 64-bit applications use a 32-bit value for type long. To get 64-bits, you need to use long long on VC++. The main thing about the size of size_t, that you can count on, is that sizeof(size_t) >= sizeof(void*).
    What can this strange device be?
    When I touch it, it gives forth a sound
    It's got wires that vibrate and give music
    What can this thing be that I found?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. size_t
    By bos1234 in forum C Programming
    Replies: 1
    Last Post: 03-04-2011, 05:43 AM
  2. what is size_t?
    By droseman in forum C Programming
    Replies: 4
    Last Post: 01-27-2009, 11:34 AM
  3. when to use size_t ?
    By broli86 in forum C Programming
    Replies: 3
    Last Post: 06-27-2008, 10:13 AM
  4. size_t help
    By Xanz1441 in forum C++ Programming
    Replies: 19
    Last Post: 11-03-2007, 02:25 AM
  5. size_t
    By falconetti in forum C Programming
    Replies: 2
    Last Post: 02-25-2002, 08:52 AM