Solved

size_t

Posted on 2013-11-13
4
292 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 33

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 7

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 7

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
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.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

914 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now