Re: C89, size_t, and long



Yevgen Muntyan <muntyan.removethis@xxxxxxxx> wrote:

Richard Bos wrote:
Yevgen Muntyan <muntyan.removethis@xxxxxxxx> wrote:

Richard Bos wrote:
Yevgen Muntyan <muntyan.removethis@xxxxxxxx> wrote:

But how is casting size_t to unsigned long more legitimate than

int process_some_data (char *data, unsigned long len);
In this case, you could easily make len a size_t instead.
*If* I can change the code.

If _you_ can't change the code, I would advise not to worry about
whether the ideas expressed in it are legitimate or not; leave that to
the people who did design and do maintain it.

That's good and everything, but doesn't always work on practice
unfortunately. If I happen to use some library which uses long instead
of ssize_t, and if I happen to get a dll of that library, I have a
problem.

(If you use ssize_t at all, you have a problem, because that's not an
ISO type and the idea behind it is broken; the only valid reason to have
it in the first place is covered by ptrdiff_t.)

However, if you use a library and you find you can't trust it, your
options are basically to choose a different library, to roll your own,
or to accept that your supervisor doesn't know what he's talking about
and drink the flavorade. Discussing with yourself whether there's a
theoretical possibility of brokenness when you already know that you
will not be able to stop the breakage is reason to file a defect report
with your managers, not reason to fret about it.

By the way, it seems that some people avoid #includ'ing headers like
stddef.h in library headers due to bugs in C implementations
or for some other obscure reasons. I'd think it adds to this
issue: you can use long for free, it's builtin, but to get
size_t you need an extra header.

Given that size_t is also #defined in <stdio.h>, <stdlib.h> and
<string.h>, probably the three most #included headers, without which I
can hardly imagine a useful ISO C program of any reasonable size, as
well as in <time.h> and <wchar.h>, IMO people who do this should do a
reality check.

Perhaps. Or maybe it's because many vendors put lot of non-standard
stuff into standard headers. Say, if you #include <string.h> and
do not #define _GNU_SOURCE with glibc, then you don't get strndup()
declaration.

So? What does that have to do with the price of fish?

You need functions from <string.h>, you #include <string.h>, and you get
size_t for free. Ditto with <stdio.h>, and all the others. If you choose
not to #include a header you should #include because you just _might_
one day have to deal with Ganuck, the difference between unsigned long
and size_t is the least of your problems; getting a grip on your
priorities is much more important.

Richard
.



Relevant Pages

  • Re: C89, size_t, and long
    ... ISO type and the idea behind it is broken; the only valid reason to have ... theoretical possibility of brokenness when you already know that you ... stddef.h in library headers due to bugs in C implementations ... solely on guarantees made by the C standard. ...
    (comp.lang.c)
  • Re: Using GDI+ in C++
    ... out how to modify library or API headers. ... that purpose, today, the compiler has a few options that ... The reason for it can be seen by looking at the output of: ... the definitions of the symbols mentioned in the complaints. ...
    (microsoft.public.vc.language)
  • Re: Why is it that 1962-1970 seems like ages when 2000-2008 seems like Five Bloody minutes
    ... I'm puzzled cause I've never used a newsreader, nor the saw the reason ... single button and a new window pops up for me to compose in, ... list AND an individual message open at the same time. ... headers at a time, because if it goes over like 25 messages or whatever, it ...
    (rec.music.beatles)
  • Re: Using GDI+ in C++
    ... > out how to modify library or API headers. ... the exact reason for the failures is not important; ... > that purpose, today, the compiler has a few options that ... > the definitions of the symbols mentioned in the complaints. ...
    (microsoft.public.vc.language)
  • Re: Brian Kernighan, maybe Im not worthy, maybe Im scum
    ... escape sequences (which would in any case break their conformance to the ... Question 16 is trivial if you discount the possibility that the break ... Nor is there any reason why you couldn't use structs to implement a ... Given the brokenness of the rest of it, however, I do not find that ...
    (comp.programming)