Re: Mixing size_t and other types
- From: Ian Collins <ian-news@xxxxxxxxxxx>
- Date: Sun, 01 Aug 2010 21:35:46 +1200
On 08/ 1/10 09:31 PM, Navaneeth wrote:
Hello,
I have a variable
long int size;
Value of this variable will be the size of a file which I am trying to
load into memory. Now I need to allocate memory using malloc. If I
write
malloc(size);
compiler warns about "conversion to ‘size_t’ from ‘long int’ may
change the sign of the result". So I added an explicit cast like
malloc((size_t) size);
I am not sure that this is the correct approach. Is this casting OK?
How can I find out the value of size_t?
Strangely enough, size_t is commonly used for sizes, so just make size a size_t and save to agro.
size_t will be an unsigned type.
--
Ian Collins
.
- Follow-Ups:
- Re: Mixing size_t and other types
- From: Malcolm McLean
- Re: Mixing size_t and other types
- From: Navaneeth
- Re: Mixing size_t and other types
- References:
- Mixing size_t and other types
- From: Navaneeth
- Mixing size_t and other types
- Prev by Date: Mixing size_t and other types
- Next by Date: Re: Mixing size_t and other types
- Previous by thread: Mixing size_t and other types
- Next by thread: Re: Mixing size_t and other types
- Index(es):
Relevant Pages
|