Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

allocating memory

Name: Anonymous 2008-10-21 23:16

have this pointer
Char *ptr
i allocate memory as
ptr = (char *) malloc (sizeof(char) * 100);
say later on in the program i may or may not need to store more characters so i'll use realloc to assign more memory. How can i find out how much memory is currently assigned to ptr so i cant find if i need to resize it or not.

Name: Anonymous 2008-10-23 3:49

>>37,39
man gcc

Name: Anonymous 2008-10-23 4:01

Better to use ssize_t just in case memory ever gets that large.
no.
http://www.opengroup.org/onlinepubs/000095399/basedefs/sys/types.h.html
size_t
    Used for sizes of objects.
ssize_t
    Used for a count of bytes or an error indication.

size_t is the correct type to use in this case, since it won't be used to store an error indication.
also, malloc() and realloc() take size_t arguments, not ssize_t:
http://www.opengroup.org/onlinepubs/000095399/functions/malloc.html
http://www.opengroup.org/onlinepubs/000095399/functions/realloc.html

>>39-40
man ed

Name: Anonymous 2008-10-23 5:49

>>30
WHich is different from malloc() how exactly?  Apart from vector<> giving you automatic clean-up, as well as the same contiguity guarantee.

Name: Anonymous 2008-10-23 16:20

>>40,42
man emacs

Name: Anonymous 2008-10-23 16:59

>>17
Ah, so Sepples' pointers can be different sizes. Great. That's why Sepples requires casts to/from void*, and C doesn't, because in C all pointers are the same size.

OK, people, we've solved it. Nothing to see here.

Name: Anonymous 2008-10-23 17:55

>>45
Wrong. The char pointers and void * must have the same size, and so do all struct pointers; but otherwise different pointer types can have different sizes.

Name: Anonymous 2008-10-23 19:39

>>46
In C++, yes. Show me some C code that demonstrates pointers of different sizes, and I'll believe you.

Name: Anonymous 2008-10-23 20:13

>>47
all pointers are the same size in most implementations, but the only thing the standard guarantees about the sizes of pointers is that void * and intptr_t (and therefore also intmax_t) are large enough to hold the value of any pointer.

Name: Anonymous 2008-10-23 20:47

>>45
No, it's just that Sepples requires explicit downcasts. This is because Sepples strives to have a stronger type system than C, even if only slightly.

Name: Anonymous 2008-10-23 21:24

Sepples strives to have a stronger type system than C
http://dis.4chan.org/read/prog/1223722258

Name: Anonymous 2008-10-23 21:40

>>21
Enjoy your Sepplesox, you raging slow-ass-fucking faggot.

Name: Anonymous 2008-10-23 21:44

>>1
Using Char is a syntax error.

Name: Anonymous 2008-10-23 23:09

>>52
Or a type mismatch.

Name: Sigmund F. 2008-10-24 1:30

>>53
Or a nasty case of class envy.

Name: Anonymous 2008-10-24 10:28

>>54
Well you know, sometimes an instance is just an instance.

Name: Anonymous 2009-07-21 2:04

-wundef.

Name: Anonymous 2010-12-06 9:32

Back to /b/, ``GNAA Faggot''

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List