H
Harsimran
Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?
between malloc and calloc .Which is better ?
Can any one explain what are far pointers ...
and what is the difference between malloc and calloc .Which is better ?
Harsimran said:Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?
Chris Torek said:Which is better, chocolate or strawberry; coconut or soy sauce;
a hammer or a wrench?
If you need bytes pre-set to '\0' you can use calloc(); if you just
need bytes, use malloc().
Mabden said:Can anyone come up with a good reason to zero out "raw" memory before you've
even used it? ...maybe to make sure there are zeroes in the empty
byte-aligned null space???
Harsimran said:Can any one explain what are far pointers
and what is the difference
between malloc and calloc .Which is better ?
It may have something to do with Borland.
Needing an array of ints (or long ints) with all elements
initialized to 0 is more or less the only time I use calloc().
^^^^^^^ ^^^^^^^Joona said:Far pointers are not an ISO standard C concept and are thus off-topic
here. There are two differences between malloc and calloc:
1) malloc excepts one parameter, calloc excepts two. The size that
While that may work for you, it is not guaranteed by the standard.
While that may work for you, it is not guaranteed by the standard.
Harsimran said:Can any one explain what are far pointers and what is the difference
between malloc and calloc .Which is better ?
or in *286* compatible protected mode.Emmanuel said:pete wrote on 12/08/04 :
Not only. It has somehing to do with x86 arch in real mode.
and what is the difference between malloc and calloc .Which is better ?
While that may work for you, it is not guaranteed by the standard.
However, unsigned types are guaranteed to have pure binary
representations, which means that memsetting an 'unsigned int' to
zero /will/ set its value to the unsigned integer zero! Ditto
'unsigned char', 'unsigned long', et cetera. (And I think ditto
the new C99 fixed-width types: 'int32_t' and 'int_least8_t' and
friends.)
Arthur J. O'Dwyer said:.... snip ...
However, unsigned types are guaranteed to have pure binary
representations, which means that memsetting an 'unsigned int' to
zero /will/ set its value to the unsigned integer zero! Ditto
'unsigned char', 'unsigned long', et cetera. (And I think ditto
the new C99 fixed-width types: 'int32_t' and 'int_least8_t' and
friends.)
I often use 'calloc' in image processing; for example, to get
a grayscale image of size w*h initialized to black, I'll write
unsigned char *im = calloc(w*h, 1);
So 'calloc' does have its uses; they're just rare.
CBFalconer said:^^^^^^^ ^^^^^^^
accepts
Michael said:The signed integer types are required to have the same representation
as their corresponding unsigned types for values that both types can
represent (C99 6.1.2.5).
Thus the signed integer types' zeros must also be all-bits-zero.
Further, the "pure binary numeration system" requirement applies to
all integral types, not just unsigned ones (also 6.1.2.5).
Michael said:.... snip ...
Isn't it? I thought we had agreed that in effect the only integer
representations that met the standard's requirements were sign-
magnitude, one's-complement, and two's-complement. In all three,
all-bits-zero is a representation for value 0; the first two can
also express "negative zero", but I was under the impression that
the rule requiring same representation for corresponding signed and
unsigned types ruled out "negative zero" as the canonical represen-
tation for value 0.
In short, initializing an array of ints or long ints to all-bits-
zero should, AFAICT, initialize each member of the array to value
0 on any conforming implementation. What am I missing?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.