Solved

size_t

Posted on 2013-11-13
4
305 Views
Last Modified: 2013-11-22
Hi

I am trying to see what the implementation definition  of size_t is in my project. I tried searching by typedef.*size_t and also using.*size_t but I found no results. Could size_t be defined by default somewhere? I expected to see it in a (C++) header file and I was expecting it to be programmer defined.

Am i incorrect in assuming it is defined for the project by the programmer? And if so, where else should I be looking for its definition?

thanks
0
Comment
Question by:LuckyLucks
  • 2
4 Comments
 
LVL 34

Accepted Solution

by:
sarabande earned 500 total points
ID: 39645670
it depends on your compiler whether it is a built-in type like int or double or if it was a typedef.

at windows platform the vc compiler defines it in a c++ header like

#ifndef _SIZE_T_DEFINED
#ifdef  _WIN64
typedef unsigned __int64    size_t;
#else
typedef _W64 unsigned int   size_t;
#endif
#define _SIZE_T_DEFINED
#endif

Open in new window



by use of sizeof you would find out whether it is 32-bit or 64-bit. newer compilers always should use 64-bit. signed or unsigned you may find out by assigning -1 and 0 to size_t variables and compare them.

Sara
0
 
LVL 86

Expert Comment

by:jkr
ID: 39645690
>>I am trying to see what the implementation definition  of size_t is in my project

What about

std::cout << "The size of 'size_t' is " << sizeof(size_t) << std::endl;

Open in new window


or

printf("The size of 'size_t' is %d\n", sizeof(size_t));

Open in new window


respectively?
0
 
LVL 8

Expert Comment

by:Murugesan Nagarajan
ID: 39653105
It depends upon the search command being used to find size_t
I have used the following command in my Linux machine:
/usr/bin/find /usr/include/ -type f -name "*.h" -exec /bin/egrep -l "typedef.*unsigned long.*size_t" {} \;

Open in new window

/usr/include/asm-x86_64/posix_types.h

/usr/bin/find /usr/include/ -type f -name "*.h" -exec /bin/egrep "typedef.*unsigned long.*size_t" {} \;

Open in new window

typedef unsigned long   __kernel_size_t;

/usr/bin/find /usr/include/ -type f -name "*.h" -exec /bin/egrep -l "typedef.*__kernel_size_t.*size_t" {} \;

Open in new window

/usr/include/linux/types.h

/usr/bin/find /usr/include/ -type f -name "*.h" -exec /bin/egrep "typedef.*__kernel_size_t.*size_t" {} \;

Open in new window

typedef __kernel_size_t         size_t;


My machine details:
/bin/cat /etc/redhat-release

Open in new window

CentOS release 5.5 (Final)

/bin/uname -sm

Open in new window

Linux x86_64
0
 
LVL 8

Expert Comment

by:Murugesan Nagarajan
ID: 39653112
Knowing the type of size_t using gdb

$ /bin/cat  know_Type_size_t.c

Open in new window



#include <stdio.h>
int main( )
{
        size_t checkThisType = 0;
        printf( "%d\n", checkThisType);
        return 0;
}

Open in new window



Compilation:
/usr/bin/gcc -g know_Type_size_t.c -o a.out

Open in new window

With or without "-o a.out" above, binary name created is a.out



/usr/bin/gdb -q a.out
(gdb) break main
Breakpoint 1 at 0x4004a0: file know_Type_size_t.c, line 4.
(gdb) run
Starting program: a.out
Breakpoint 1, main () at know_Type_size_t.c:4
4               size_t checkThisType = 0;
(gdb) ptype checkThisType
type = long unsigned int

Open in new window





Using dbx, use the following instead of "break main"
stop in main

Open in new window

0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Handle Exceptions during instantiation 28 428
VS2015 compilation and missing DLLs 9 181
FMX StringGrid1->Canvas->FillRect Problem 3 197
Safe conversion? 4 75
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

756 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question