-
Lol. It works in MSVC 6.0. Yea, I know. It's outdated. Check out some code that runs with flying colors in MSVC 6.0. I apologize in advance for casting malloc.
Code:
#include <stdio.h>
#include <stdlib.h>
#include <malloc.h>
int main()
{
int *lpArray = (int*)malloc(sizeof(lpArray) * 101);
size_t sizeArray = _msize(lpArray) / sizeof(lpArray);
printf("lpArray has a size of %d.\n", sizeArray);
return 0;
}
[edit]Ye Old Popular Search Engine[/edit]
-
Ah, my font makes it look like it's all run together: "size_t_msize", which is why I didn't find anything on it.
Quzah.
-
PellesC, LCC & LCC~Win32 have it in stdlib.h
Code:
/* private extensions to standard C */
//...
size_t __cdecl _msize(void *);
-
I found it inside MALLOC.h for the Win32 version of LCC.
Borland supports it, too, under malloc.h.
Can anyone find a popular compiler that does not support it? I'd be interested in knowing how portable this is.
-
Oh, I don't know...
Quzah.
-
> I'd be interested in knowing how portable this is.
The fact that it begins with an _ should tell you all you need to know about how useful that function is.
Why is it so hard to store the parameter you passed to malloc in the first place in another variable?
-
-
Quote:
Originally Posted by
RakeshKhanna
Try using
strlen(String)
I suppose you didn't read the earlier posts?