Re: reporting typedef errors automatically

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Roman Mashak

    Re: reporting typedef errors automatically

    Hello, Jack!
    You wrote on Thu, 29 May 2008 20:38:35 -0500:

    JKThis is a pretty stupid idea, and extremely non-portable. Who's
    JKnot-so-bright idea is it?
    Build the skills your teams need. Give them the O'Reilly learning platform and equip them with the resources that drive business outcomes.


    [skip]
    What portable way would you suggest? Checking the CHAR_BITS?

    With best regards, Roman Mashak. E-mail: mrv@tusur.ru


  • Chris Thomasson

    #2
    Re: reporting typedef errors automatically


    "Roman Mashak" <mrv@tusur.ruwr ote in message
    news:g1nsl5$6no $1@relay.tomsk. ru...
    Hello, Jack!
    You wrote on Thu, 29 May 2008 20:38:35 -0500:
    >
    JKThis is a pretty stupid idea, and extremely non-portable. Who's
    JKnot-so-bright idea is it?
    Build the skills your teams need. Give them the O'Reilly learning platform and equip them with the resources that drive business outcomes.

    >
    [skip]
    What portable way would you suggest? Checking the CHAR_BITS?
    [...]

    Try something like:



    #include <limits.h>

    typedef char atomic_word8;
    typedef short atomic_word16;
    typedef int atomic_word32;

    typedef char atomic_word_siz eof_static_asse rt[
    sizeof(atomic_w ord8) == 8 / CHAR_BIT &&
    sizeof(atomic_w ord16) == 16 / CHAR_BIT &&
    sizeof(atomic_w ord32) == 32 / CHAR_BIT
    ? 1 : -1
    ];



    Comment

    • Jack Klein

      #3
      Re: reporting typedef errors automatically

      On Fri, 30 May 2008 12:34:30 -0700, "Roman Mashak" <mrv@tusur.ru >
      wrote in comp.lang.c:
      Hello, Jack!
      You wrote on Thu, 29 May 2008 20:38:35 -0500:
      >
      JKThis is a pretty stupid idea, and extremely non-portable. Who's
      JKnot-so-bright idea is it?
      Build the skills your teams need. Give them the O'Reilly learning platform and equip them with the resources that drive business outcomes.

      >
      [skip]
      What portable way would you suggest? Checking the CHAR_BITS?
      The header <stdint.hprovid es minimum and maximum macros for the
      exact width integer types, if and only if those particular types are
      defined.

      As someone else already pointed out, if int8_t and uint8_t exist, the
      wider types, if they exist as they almost certainly will, will have
      the sizes you check for.

      Still, it's much easier to do something like this:

      #include <stdint.h>

      #ifndef INT8_MAX

      ....do something about it

      #endif

      But if the types you need are there, why do you care what their sizes
      are in bytes? Are you actually expecting a compiler to come with
      errors in its <stdint.hheader ?

      In the Barr article you quote, he is talking about a way of testing a
      home brew <stdint.hfor a compiler that doesn't come with one.
      Frankly, anybody who can't get this right on the first try probably
      shouldn't be trying.

      --
      Jack Klein
      Home: http://JK-Technology.Com
      FAQs for
      comp.lang.c http://c-faq.com/
      comp.lang.c++ http://www.parashift.com/c++-faq-lite/
      alt.comp.lang.l earn.c-c++

      Comment

      • Roman Mashak

        #4
        Re: reporting typedef errors automatically

        Hello, Jack!
        You wrote on Fri, 30 May 2008 21:41:48 -0500:

        ??>Hello, Jack!
        ??>You wrote on Thu, 29 May 2008 20:38:35 -0500:
        ??>>
        JK>>This is a pretty stupid idea, and extremely non-portable. Who's
        JK>>not-so-bright idea is it?
        ??>http://www.oreillynet.com/pub/a/netw...hael_barr.html
        ??>>
        ??>[skip]
        ??>What portable way would you suggest? Checking the CHAR_BITS?

        JKThe header <stdint.hprovid es minimum and maximum macros for the
        JKexact width integer types, if and only if those particular types are
        JKdefined.
        [skip]
        I got this yet, thanks though.


        With best regards, Roman Mashak. E-mail: mrv@tusur.ru


        Comment

        Working...