Hi Everyone,
I was looking at the function prototype of malloc() function in
stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
Thanks in advance. 13 1561
On 13 Jan 2007 01:39:22 -0800, sa*****@yahoo.c o.in wrote:
>Hi Everyone,
I was looking at the function prototype of malloc() function in stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
Thanks in advance.
size_t is a pre-defined type, which, according to the C Standard, is
"the unsigned integral type of the result of the sizeof operator". The
type size_t is unsigned, and it cannot possibly be defined as type
int, which must be signed.
--
jay
sam_...@yahoo.c o.in wrote:
Hi Everyone,
I was looking at the function prototype of malloc() function in
stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
size_t is a typedef for some unsigned integer type meant to be capable
of storing the size of objects. It is not pre-defined: it is defined in
several of the standard headers, but if you don't include any of them,
you're free to use size_t as an ordinary identifier in your own code.
Which specific type it has depends on the implementation, and it would
be best not to assume anything more than you need to about it.
Harald van D?k wrote:
sam_...@yahoo.c o.in wrote:
>I was looking at the function prototype of malloc() function in stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
size_t is a typedef for some unsigned integer type meant to be
capable of storing the size of objects. It is not pre-defined: it
is defined in several of the standard headers, but if you don't
include any of them, you're free to use size_t as an ordinary
identifier in your own code. Which specific type it has depends
on the implementation, and it would be best not to assume
anything more than you need to about it.
No, you are not free to use it for other purposes. You MAY get
away with it on some implementations . You are not free to use
anything defined in any standard headers.
--
"The most amazing achievement of the computer software industry
is its continuing cancellation of the steady and staggering
gains made by the computer hardware industry..." - Petroski
CBFalconer wrote:
Harald van D?k wrote:
sam_...@yahoo.c o.in wrote:
I was looking at the function prototype of malloc() function in
stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
size_t is a typedef for some unsigned integer type meant to be
capable of storing the size of objects. It is not pre-defined: it
is defined in several of the standard headers, but if you don't
include any of them, you're free to use size_t as an ordinary
identifier in your own code. Which specific type it has depends
on the implementation, and it would be best not to assume
anything more than you need to about it.
No, you are not free to use it for other purposes. You MAY get
away with it on some implementations . You are not free to use
anything defined in any standard headers.
Citation, please?
jaysome wrote:
On 13 Jan 2007 01:39:22 -0800, sa*****@yahoo.c o.in wrote:
>Hi Everyone,
I was looking at the function prototype of malloc() function in stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
Thanks in advance.
size_t is a pre-defined type, which, according to the C Standard, is
"the unsigned integral type of the result of the sizeof operator". The
type size_t is unsigned, and it cannot possibly be defined as type
int, which must be signed.
A minor clarification: size_t is "pre-defined" if you include
one or more of the headers that define it, but is not "baked in"
to the compiler in the way sizeof is. The following is a legal C
function, albeit a stupid one:
#include <math.h>
double size_t(double FILE, double NULL, double offsetof) {
return (-NULL + sqrt(NULL*NULL - 4*FILE*offsetof ))
/ (2*FILE);
}
The following translation unit is not legal C:
/* no header inclusions */
size_t elementCount(si ze_t arraySize, size_t elementSize) {
return arraySize / elementSize;
}
.... because size_t is not defined.
--
Eric Sosman es*****@acm-dot-org.invalid sa*****@yahoo.c o.in wrote:
Hi Everyone,
I was looking at the function prototype of malloc() function in
stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
It can't be. 'int' is a signed integer type; 'size_t' is an unsigned
integer type.
Harald van D?k wrote:
CBFalconer wrote:
>Harald van D?k wrote:
>>sam_...@yahoo .co.in wrote:
I was looking at the function prototype of malloc() function in stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
size_t is a typedef for some unsigned integer type meant to be capable of storing the size of objects. It is not pre-defined: it is defined in several of the standard headers, but if you don't include any of them, you're free to use size_t as an ordinary identifier in your own code. Which specific type it has depends on the implementation, and it would be best not to assume anything more than you need to about it.
No, you are not free to use it for other purposes. You MAY get away with it on some implementations . You are not free to use anything defined in any standard headers.
Citation, please?
>From N869:
7.1.3 Reserved identifiers
[#1] Each header declares or defines all identifiers listed
in its associated subclause, and optionally declares or
defines identifiers listed in its associated future library
directions subclause and identifiers which are always
reserved either for any use or for use as file scope
identifiers.
-- All identifiers that begin with an underscore and
either an uppercase letter or another underscore are
always reserved for any use.
-- All identifiers that begin with an underscore are
always reserved for use as identifiers with file scope
in both the ordinary and tag name spaces.
-- Each macro name in any of the following subclauses
(including the future library directions) is reserved
for use as specified if any of its associated headers
is included; unless explicitly stated otherwise (see
7.1.4).
-- All identifiers with external linkage in any of the
following subclauses (including the future library
directions) are always reserved for use as identifiers
with external linkage.143)
_______________ _____
143The list of reserved identifiers with external linkage
includes errno, setjmp, and va_end.
--
"The most amazing achievement of the computer software industry
is its continuing cancellation of the steady and staggering
gains made by the computer hardware industry..." - Petroski
CBFalconer wrote:
Harald van D?k wrote:
CBFalconer wrote:
Harald van D?k wrote: sam_...@yahoo. co.in wrote:
I was looking at the function prototype of malloc() function in stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
size_t is a typedef for some unsigned integer type meant to be capable of storing the size of objects. It is not pre-defined: it is defined in several of the standard headers, but if you don't include any of them, you're free to use size_t as an ordinary identifier in your own code. Which specific type it has depends on the implementation, and it would be best not to assume anything more than you need to about it.
No, you are not free to use it for other purposes. You MAY get
away with it on some implementations . You are not free to use
anything defined in any standard headers.
Citation, please?
From N869:
7.1.3 Reserved identifiers
7.1.3 applies, but the part that applies is what follows the list of
cases: "No other identifiers are reserved." size_t does not start with
an underscore, its header is not included, and the standard definition
of it has no linkage, so none of the cases that say identifiers are
reserved apply. (You missed one, by the way.)
CBFalconer wrote:
Harald van D?k wrote:
CBFalconer wrote:
Harald van D?k wrote: sam_...@yahoo. co.in wrote:
I was looking at the function prototype of malloc() function in stdlib.h and i found that to be,
void *malloc(size_t size);
so what is size_t is it a pre-defined typedef to int?
size_t is a typedef for some unsigned integer type meant to be capable of storing the size of objects. It is not pre-defined: it is defined in several of the standard headers, but if you don't include any of them, you're free to use size_t as an ordinary identifier in your own code. Which specific type it has depends on the implementation, and it would be best not to assume anything more than you need to about it.
No, you are not free to use it for other purposes. You MAY get
away with it on some implementations . You are not free to use
anything defined in any standard headers.
Citation, please?
From N869:
7.1.3 Reserved identifiers
[#1] Each header declares or defines all identifiers listed
in its associated subclause, and optionally declares or
defines identifiers listed in its associated future library
directions subclause and identifiers which are always
reserved either for any use or for use as file scope
identifiers.
-- All identifiers that begin with an underscore and
either an uppercase letter or another underscore are
always reserved for any use.
-- All identifiers that begin with an underscore are
always reserved for use as identifiers with file scope
in both the ordinary and tag name spaces.
-- Each macro name in any of the following subclauses
(including the future library directions) is reserved
for use as specified if any of its associated headers
is included; unless explicitly stated otherwise (see
7.1.4).
-- All identifiers with external linkage in any of the
following subclauses (including the future library
directions) are always reserved for use as identifiers
with external linkage.143)
_______________ _____
143The list of reserved identifiers with external linkage
includes errno, setjmp, and va_end.
You left out
-- Each identifier with file scope listed in any of the following
subclauses (including the future library directions) is reserved
for use as a macro name and as an identifier with file scope in
the same name space if any of its associated headers is included.
So which case applies to an identifier that does not start with _, does
not have its header included, and the standard definition of which has
no linkage? (My apologies if I reply to your message more than once;
I'm having some problems.) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: xuatla |
last post by:
Hi,
I am not sure whether I describe the subject correctly.
What I want to do is for a matrix class
---------------------------
class CMatrix
{
private:
|
by: Alex Vinokur |
last post by:
Why was the size_t type defined in compilers in addition to unsigned
int/long?
When/why should one use size_t?
Alex Vinokur
email: alex DOT vinokur AT gmail DOT com
http://mathforum.org/library/view/10978.html
http://sourceforge.net/users/alexvn
|
by: raghu |
last post by:
Hello Every one,
I am writing a program in gcc compiler which contains many
functions. In main I created memory for a variable and tried to free
in another function. But I am getting error as segmentation fault at
some times or glibc free Invalid Pointer at some times. Can any one of
you help me out. But I must free the data.
A(){
mem= (char *)malloc(sizeof(char));
|
by: somenath |
last post by:
Hi All,
I am trying to understand the behavior of the memcpy and memmove.
While doing so I wrote a program as mentioned bellow .
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE_OF_DST 3
int main(void)
|
by: somenath |
last post by:
Hi All,
I was trying to write a function which will read one line from a
specified file and return the line. It is currently working fine.
But it would be very much helpful for me if some one point out some
improvement points or some error in the code.
Regards,
Somenath
| |
by: Tubular Technician |
last post by:
Hello, World!
Reading this group for some time I came to the conclusion that
people here are split into several fractions regarding size_t,
including, but not limited to,
* size_t is the right thing to use for every var that holds the
number of or size in bytes of things.
* size_t should only be used when dealing with library functions.
|
by: venkat |
last post by:
Hi,
i came across restrict qualifier while looking the code. I haven't
able to understand what does this do?. Can some one help me how does
this makes the things restrict to an specified objects. It will be
good, if explained with example.
Appriciate your help in this regard.
Thanks,
|
by: Giuseppe:G: |
last post by:
Hi, any idea on what is this code doing:
//=================================
1 #include <boost/scoped_ptr.hpp>
....
3 typedef std::vector<std::vector<pair<size_t, size_t ParamsType;
5 /*
|
by: PeterAPIIT |
last post by:
Hello all C++ expert programmer,
i have wrote partial general allocator for my container.
After reading standard C++ library and code guru article, i have
several questions.
1. Why allocator write forward declaration then allocation for void*
rather than directly wrote allocator first ?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |