Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #171740

Re: Baby X resource compiler nearly ready

From Keith Thompson <Keith.S.Thompson+u@gmail.com>
Newsgroups comp.lang.c
Subject Re: Baby X resource compiler nearly ready
Date 2023-08-06 14:03 -0700
Organization None to speak of
Message-ID <87h6pbkhoa.fsf@nosuchdomain.example.com> (permalink)
References (1 earlier) <644ac909-d6b9-42b9-88c0-1442b6fd227an@googlegroups.com> <87wmy9rwi8.fsf@bsb.me.uk> <a4b1ffc5-2ec6-463e-8c69-bb41c6f4f38cn@googlegroups.com> <uanuhp$3770n$1@news.xmission.com> <da68fd88-8d75-4601-bd7d-71d4109bf416n@googlegroups.com>

Show all headers | View raw


Malcolm McLean <malcolm.arthur.mclean@gmail.com> writes:
[...]
> The a basic problem was that I am using a MP3 decoder written by someone else.
> They wrote a file called clib.h which has various efficiency and portability hacks.
> It includes this
>
> #if !NEED_MINILIBC
>     #include <stdio.h>
>     #include <stdlib.h>
>     #include <string.h>
> #endif
> #include <math.h>
>
> #ifndef __int8_t_defined
>     #define __int8_t_defined
>     typedef unsigned char  uint8_t;
>     typedef   signed char   int8_t;
>     typedef unsigned short uint16_t;
>     typedef   signed short  int16_t;
>     typedef unsigned int   uint32_t;
>     typedef   signed int    int32_t;
>     #ifdef _MSC_VER
>         typedef unsigned __int64 uint64_t;
>         typedef   signed __int64  int64_t;
>     #else
>         typedef unsigned long long uint64_t;
>         typedef   signed long long  int64_t;
>     #endif
> #endif

This code assumes that the macro __int8_t_defined is defined if and only
if the fixed-width types from <stdint.h> are defined.  There's no basis
for that assumption -- *unless* there's some other code we haven't seen
that sets __int8_t_defined appropriately.  For example, there might be a
build step that write a small C source file that uses int8_t, then
writes a C header file whose contents depend on whether that source file
compiles or not.  Perhaps the code that does that breaks on Linux.

Or perhaps it assume that <stdint.h> defines a macro __int8_t_defined.
Some implementations might do so, but it's a bad assumption.

It's not guaranteed that int8_t exists even if <stdint.h> exists (if
CHAR_BIT==8 or signed char doesn't use two's-complement).  You can check
for that with `#ifdef INT8_MAX`.

If the code is intended to cater to pre-C99 implementations, the problem
is that the <stdint.h> header may not exist, and there's no way in C to
test whether a given header exists or not.  (C23 adds __has_include(),
but of course if you have __has_include() you have <stdint.h> anyway.)

These days, it's likely safe enough to just assume that you have
<stdint.h>.  Even a pre-C99 implementation is likely to provide it as an
extension.  Or, if you really need it, you can look at Doug Gwyn's old
q8, which provides some C99 headers for use with C90 implementations:
    https://www.lysator.liu.se/c/q8/index.html
Or you can check that __STDC_VERSION__ >= 199901L.

> Linux include <stdint.h> from the system headers. Windows and Mac doesn't.
> So this breaks when compiled on Linux. By trying to be portable, they managed
> to produce something which wasn't portable.

What does that mean?

> It really confirms my view that it's best to write in a conservative subset of C90
> and the subsequent standards. otherwise you just get endless trouble. But writing
> my own MP3 decoder would be a huge job (I've written one before, but it was for
> work so of course I can't put it on the web). 

It's likely that just assuming C99 or later would have avoided this
problem in the first place.

-- 
Keith Thompson (The_Other_Keith) Keith.S.Thompson+u@gmail.com
Will write code for food.
void Void(void) { Void(); } /* The recursive call of the void */

Back to comp.lang.c | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 02:59 -0700
  Re: Baby X resource compiler nearly ready fir <profesor.fir@gmail.com> - 2023-08-05 03:20 -0700
    Re: Baby X resource compiler nearly ready fir <profesor.fir@gmail.com> - 2023-08-05 03:28 -0700
      Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 03:42 -0700
    Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 03:41 -0700
      Re: Baby X resource compiler nearly ready fir <profesor.fir@gmail.com> - 2023-08-05 03:46 -0700
        Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 03:57 -0700
          Re: Baby X resource compiler nearly ready fir <profesor.fir@gmail.com> - 2023-08-05 05:28 -0700
            Re: Baby X resource compiler nearly ready fir <profesor.fir@gmail.com> - 2023-08-05 06:01 -0700
      Re: Baby X resource compiler nearly ready fir <profesor.fir@gmail.com> - 2023-08-05 03:49 -0700
      Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-05 12:29 +0100
        Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 04:38 -0700
  Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-05 12:17 +0100
    Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 04:19 -0700
      Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-05 20:33 +0100
        Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-05 12:39 -0700
          Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-05 22:48 +0100
            Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-06 03:21 -0700
              Re: Baby X resource compiler nearly ready gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-06 11:01 +0000
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-06 04:36 -0700
                Re: Baby X resource compiler nearly ready Spiros Bousbouras <spibou@gmail.com> - 2023-08-06 12:52 +0000
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-06 06:04 -0700
                Re: Baby X resource compiler nearly ready gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-06 13:52 +0000
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-06 07:07 -0700
                Re: Baby X resource compiler nearly ready gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-06 14:47 +0000
                Re: Baby X resource compiler nearly ready Bart <bc@freeuk.com> - 2023-08-06 16:18 +0100
                Re: Baby X resource compiler nearly ready Kaz Kylheku <864-117-4973@kylheku.com> - 2023-08-06 16:29 +0000
                Re: Baby X resource compiler nearly ready David Brown <david.brown@hesbynett.no> - 2023-08-08 16:52 +0200
                Re: Baby X resource compiler nearly ready Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-08 16:37 -0700
                Re: Baby X resource compiler nearly ready Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-08 16:41 -0700
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-08 19:07 -0700
                Re: Baby X resource compiler nearly ready Richard Damon <Richard@Damon-Family.org> - 2023-08-08 22:32 -0400
                Re: Baby X resource compiler nearly ready Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-08 23:36 -0700
                Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-06 16:02 +0100
                Re: Baby X resource compiler nearly ready David Brown <david.brown@hesbynett.no> - 2023-08-08 16:57 +0200
                Re: Baby X resource compiler nearly ready scott@slp53.sl.home (Scott Lurndal) - 2023-08-08 15:09 +0000
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-08 08:26 -0700
                Re: Baby X resource compiler nearly ready scott@slp53.sl.home (Scott Lurndal) - 2023-08-08 15:55 +0000
                Re: Baby X resource compiler nearly ready Tim Rentsch <tr.17687@z991.linuxsc.com> - 2023-08-08 06:03 -0700
                Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-06 14:36 +0100
                Re: Baby X resource compiler nearly ready Keith Thompson <Keith.S.Thompson+u@gmail.com> - 2023-08-06 14:03 -0700
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-07 01:41 -0700
                Re: Baby X resource compiler nearly ready jak <nospam@please.ty> - 2023-08-07 13:09 +0200
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-07 04:59 -0700
                Re: Baby X resource compiler nearly ready jak <nospam@please.ty> - 2023-08-07 16:53 +0200
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-07 08:27 -0700
                Re: Baby X resource compiler nearly ready Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2023-08-07 09:44 -0700
        Re: Baby X resource compiler nearly ready Bart <bc@freeuk.com> - 2023-08-06 16:44 +0100
          Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-06 17:56 +0100
  Re: Baby X resource compiler nearly ready scott@slp53.sl.home (Scott Lurndal) - 2023-08-05 14:38 +0000
    Re: Baby X resource compiler nearly ready gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-05 15:29 +0000
      Re: Baby X resource compiler nearly ready scott@slp53.sl.home (Scott Lurndal) - 2023-08-05 17:47 +0000
        Blah, blah, blah (Was: Baby X resource compiler nearly ready) gazelle@shell.xmission.com (Kenny McCormack) - 2023-08-05 18:44 +0000
  Re: Baby X resource compiler nearly ready Ben Bacarisse <ben.usenet@bsb.me.uk> - 2023-08-06 15:52 +0100

csiph-web