Re: It Pays to Enrich Your C Skills
- From: Dave Thompson <david.thompson1@xxxxxxxxxxxxxxxx>
- Date: 11 May 2006 05:12:45 GMT
On 02 Apr 2006 09:44:59 GMT, Jack Klein <jackklein@xxxxxxxxxxx> wrote:
On 10 Mar 2006 05:09:21 GMT, "Ganny" <sgganesh@xxxxxxxxx> wrote in
comp.lang.c.moderated:
Neither are there relationships in the standard C language, although5. For signed integers, which of the following relationships hold true?
(1) x >= 0 => -x <= 0
(2) x <= 0 => -x >= 0
(3) x > y => -x < -y
What relationship? There is no "=>" operator in C. This has no
meaning.
there are in 7.12.14 floating-point comparison operations that
implement mathematical relationships. And there is a basic logical
relationship "implies" conventionally notated =>.
Since as you note(d) on another item, C allows but does not require
2sC where INT_MIN == - INT_MAX - 1, only (1) is safe. Assuming by
signed integers he means a (consistent) signed integer type not
altered by the usual arithmetic conversions. If he really means
mathematical integers it's offtopic as well as unanswerable.
Note that he used flex as both the struct tag and an actual variable9) <insert: corresponding question was sizeof is zero>
It is for the flexible array members (FLA) of C99. (Note that the
answer is
not sizeof(void) since it's a compiler error.)
#include <stdio.h>
struct flex {
int i;
int arr[];
} flex;
int main(int argc, char *argv[]) {
printf("size of flex.arr = %d", sizeof(flex.arr));
Did you compile this? If your compiler accepted it, it is a
non-standard extension. The sizeof operator can only be applied to
types or expressions, and not to the name of a structure member, which
is neither.
(object). object.member is a valid expression. Actually as I read
6.7.2.1p16, which was apparently written to cover actual use of a FAM,
it says sizeof a FAM in a dynamically allocated object must be
computed at runtime, and in this case it would be one element ==
sizeof(int), both of which I'm confident were not intended.
He means FAM not FLA. (_V_LA is a different feature, though it uses}
// prints:
// size of flex.arr = 0
C99 specifies that only the last element of a structure can be an FLA.
The
reason why sizeof applied to the structure ignores the FLA (and hence
the
FLA size is zero) is that, this makes the malloc call simple. That is
the
allocation is as follows:
related syntax.) That a FAM is ignored in computing the sizeof the
whole struct does not necessarily have anything to its own size.
struct flex *flex_ptr =
malloc(sizeof(struct flex) + num * sizeof(int));
Here note the change that it is num * sizeof(int) and not (num-1) *
sizeof(int), so, the malloc simple.
- David.Thompson1 at worldnet.att.net
--
comp.lang.c.moderated - moderation address: clcm@xxxxxxxxxxxx -- you must
have an appropriate newsgroups line in your header for your mail to be seen,
or the newsgroup name in square brackets in the subject line. Sorry.
.
- Prev by Date: Some questions, big numbers library
- Next by Date: Re: array of pointers?
- Previous by thread: Some questions, big numbers library
- Next by thread: Re: Volatiles in assignment expressions
- Index(es):
Relevant Pages
|