Solved

size_t

Posted on 2013-11-13
4
310 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 9

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 9

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
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.

623 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