Solved

size_t

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

Independent Software Vendors: 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

Suggested Solutions

Title # Comments Views Activity
Quicksort a dynamic deque 33 82
Cross compile release version of c++ program for linux 2 146
computer science syllabus 3 115
Coding for the first time 9 100
Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

734 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