Re: C89, size_t, and long
- From: Yevgen Muntyan <muntyan.removethis@xxxxxxxx>
- Date: Fri, 16 Mar 2007 16:35:46 GMT
Richard Bos wrote:
Yevgen Muntyan <muntyan.removethis@xxxxxxxx> wrote:
Richard Bos wrote:Yevgen Muntyan <muntyan.removethis@xxxxxxxx> wrote:That's good and everything, but doesn't always work on practice
Richard Bos wrote:If _you_ can't change the code, I would advise not to worry aboutYevgen Muntyan <muntyan.removethis@xxxxxxxx> wrote:*If* I can change the code.
But how is casting size_t to unsigned long more legitimate thanIn this case, you could easily make len a size_t instead.
int process_some_data (char *data, unsigned long len);
whether the ideas expressed in it are legitimate or not; leave that to
the people who did design and do maintain it.
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.
Oh well, it's glib, and you're talking nonsense. *If* I don't trust
it lalala. I do trust it.
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.
Perhaps. Or maybe it's because many vendors put lot of non-standardBy the way, it seems that some people avoid #includ'ing headers likeGiven that size_t is also #defined in <stdio.h>, <stdlib.h> and
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.
<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.
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?
#include <glib.h>
#define _GNU_SOURCE
#include <string.h>
#undef _GNU_SOURCE
#include <stdlib.h>
void foo (void)
{
strndup ("d", 1);
}
This code is broken if glib.h #include's string.h. If you were a glib
developer (which I guess is good you aren't), you could decide it's not
a good thing. If it does need string.h (which it doesn't), it would
need to document it, and *always* include it, forever. I have no idea
what funny target platforms considerations may affect desicions like
this. glib is not a fancy standard-C-only library, and it can't rely
solely on guarantees made by the C standard.
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.
The difference between long and size_t has nothing to with this headers
business in fact. Try reading my post where I brought it in.
Yevgen
.
- References:
- C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Eric Sosman
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Eric Sosman
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Eric Sosman
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Richard Bos
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Richard Bos
- Re: C89, size_t, and long
- From: Yevgen Muntyan
- Re: C89, size_t, and long
- From: Richard Bos
- C89, size_t, and long
- Prev by Date: Re: K&R 5-1
- Next by Date: how to speed up the matrix multiplication in C
- Previous by thread: Re: C89, size_t, and long
- Next by thread: Re: C89, size_t, and long
- Index(es):
Relevant Pages
|