Types defined in std::

Discussion in 'C++' started by Andy Skypeck, Dec 4, 2003.

  1. Andy Skypeck

    Andy Skypeck Guest

    I am looking for some validation against a dubious coding practice
    that prevails where I work. C types defined in types.h (Linux) or
    stdint.h (Windows, C99?) are used as if they belong to the C++
    standard namespace.

    std::uint8_t instead of uint8_t
    std::uint32_t instead of uint32_t
    ....

    I don't think the use of std:: is correct. Nowhere are these types
    explicitly added to the std namespace. In fact GCC 3.3 fails on them.
    Neither are they among the types defined in the C++ standard language
    support files listed on page 433 in Stroustrup (2nd Ed.)

    std::size_t
    std::ptrdiff_t
    std::NULL

    defined in <cstddef> are ok. I am wrong about this?
     
    Andy Skypeck, Dec 4, 2003
    #1
    1. Advertising

  2. Andy Skypeck

    tom_usenet Guest

    On 4 Dec 2003 07:09:30 -0800, (Andy Skypeck)
    wrote:

    >I am looking for some validation against a dubious coding practice
    >that prevails where I work. C types defined in types.h (Linux) or
    >stdint.h (Windows, C99?) are used as if they belong to the C++
    >standard namespace.
    >
    >std::uint8_t instead of uint8_t
    >std::uint32_t instead of uint32_t
    >...
    >
    >I don't think the use of std:: is correct. Nowhere are these types
    >explicitly added to the std namespace. In fact GCC 3.3 fails on them.
    > Neither are they among the types defined in the C++ standard language
    >support files listed on page 433 in Stroustrup (2nd Ed.)
    >
    >std::size_t
    >std::ptrdiff_t
    >std::NULL
    >
    >defined in <cstddef> are ok. I am wrong about this?


    No, they aren't standard types in C++. They are standard in C99
    though. But since C99 doesn't have namespaces, std::uint8_t has never
    existed. std::uint8_t will probably become part of C++0x, whenever
    that is ratified (around 2007-8 I suspect), and it may be part of the
    standard library extension before that. Some compilers may be
    pre-empting that by providing the standard types, but it isn't yet
    standard.

    Tom

    C++ FAQ: http://www.parashift.com/c -faq-lite/
    C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
     
    tom_usenet, Dec 4, 2003
    #2
    1. Advertising

  3. "Andy Skypeck" <> wrote...
    > I am looking for some validation against a dubious coding practice
    > that prevails where I work.


    Take my word for it: it's better to go with the flow than against
    it. Whether your coding practice is dubious or not, it's accepted
    in the organisation, and you should do the same if you want to keep
    your job.

    > C types defined in types.h (Linux) or
    > stdint.h (Windows, C99?) are used as if they belong to the C++
    > standard namespace.
    >
    > std::uint8_t instead of uint8_t
    > std::uint32_t instead of uint32_t
    > ...
    >
    > I don't think the use of std:: is correct. Nowhere are these types
    > explicitly added to the std namespace.


    What do you mean by that?

    > In fact GCC 3.3 fails on them.


    So? How is that proof of anything?

    > Neither are they among the types defined in the C++ standard language
    > support files listed on page 433 in Stroustrup (2nd Ed.)
    >
    > std::size_t
    > std::ptrdiff_t
    > std::NULL
    >
    > defined in <cstddef> are ok. I am wrong about this?


    NULL is a macro, it cannot be defined in a namespace. The Standard
    says (17.4.1.1):

    "1 The C++ Standard Library provides definitions for the following
    types of entities: Macros, Values, Types, Templates, Classes,
    Functions, Objects.

    2 All library entities except macros, operator new and operator
    delete are defined within the namespace std or namespaces nested
    within namespace std."

    Now, there is a subclause that says "It is undefined for a C++
    program to add declarations or definitions to namespace std [...]"
    but it could be argued that types you listed (uint8_t, etc.) are
    part of the library implementation and as such belong to std...

    Why don't you ask your development supervisor where they get those
    types? They will probably be able to explain why 'std::' is used
    there.

    Victor
     
    Victor Bazarov, Dec 4, 2003
    #3
  4. Andy Skypeck

    Dan W. Guest

    On 4 Dec 2003 07:09:30 -0800, (Andy Skypeck)
    >I don't think the use of std:: is correct. Nowhere are these types
    >explicitly added to the std namespace. In fact GCC 3.3 fails on them.


    I don't think that use of the ::std namespace is an official stamp of
    approval. Take std::hashmap, for example: This is a container that's
    been living in ::std for quite a while, even though it is not yet part
    of the standard.
     
    Dan W., Dec 4, 2003
    #4
  5. Andy Skypeck

    Andy Skypeck Guest

    "Victor Bazarov" <> wrote in message news:<KuJzb.418968$HS4.3341510@attbi_s01>...
    > "Andy Skypeck" <> wrote...
    > > I am looking for some validation against a dubious coding practice
    > > that prevails where I work.

    >
    > Take my word for it: it's better to go with the flow than against
    > it. Whether your coding practice is dubious or not, it's accepted
    > in the organisation, and you should do the same if you want to keep
    > your job.


    The organisation touts itself as a quality driven "six sigma"
    environment. It seeks to write portable, robust, correct C++
    code. Questioning what to me seems to be an incorrect
    practice is very much in the spirit of the organisation.
    Correctness should win out.

    > > C types defined in types.h (Linux) or
    > > stdint.h (Windows, C99?) are used as if they belong to the C++
    > > standard namespace.
    > >
    > > std::uint8_t instead of uint8_t
    > > std::uint32_t instead of uint32_t
    > > ...
    > >
    > > I don't think the use of std:: is correct. Nowhere are these types
    > > explicitly added to the std namespace.

    >
    > What do you mean by that?
    >
    > > In fact GCC 3.3 fails on them.

    > So? How is that proof of anything?


    The release notes for GCC-3.3 discuss types included in std::

    > > Neither are they among the types defined in the C++ standard language
    > > support files listed on page 433 in Stroustrup (2nd Ed.)
    > >
    > > std::size_t
    > > std::ptrdiff_t
    > > std::NULL
    > >
    > > defined in <cstddef> are ok. I am wrong about this?

    >
    > NULL is a macro, it cannot be defined in a namespace. The Standard
    > says (17.4.1.1):


    I stand corrected on NULL.

    > Now, there is a subclause that says "It is undefined for a C++
    > program to add declarations or definitions to namespace std [...]"
    > but it could be argued that types you listed (uint8_t, etc.) are
    > part of the library implementation and as such belong to std...


    I would accept that but, as I said above, the types are defined in a
    file that is not part of the library implementation.

    > Why don't you ask your development supervisor where they get those
    > types? They will probably be able to explain why 'std::' is used
    > there.


    I have. They have an external file stdint.h defining these types.
    It is not part of any of the compilers we use. It is hand made to
    imitate the types defined for C99. Some definitions init it even
    collide with those in types.h in gcc-3.3. I have brought up this point
    repeatedly with the leads to no avail. For my own satisfaction I'd
    like to get to the bottom of this, which is why I posted.
     
    Andy Skypeck, Dec 5, 2003
    #5
  6. "Andy Skypeck" <> wrote...
    > "Victor Bazarov" <> wrote in message

    news:<KuJzb.418968$HS4.3341510@attbi_s01>...
    > > "Andy Skypeck" <> wrote...
    > > > I am looking for some validation against a dubious coding practice
    > > > that prevails where I work.

    > >
    > > Take my word for it: it's better to go with the flow than against
    > > it. Whether your coding practice is dubious or not, it's accepted
    > > in the organisation, and you should do the same if you want to keep
    > > your job.

    >
    > The organisation touts itself as a quality driven "six sigma"
    > environment. It seeks to write portable, robust, correct C++
    > code. Questioning what to me seems to be an incorrect
    > practice is very much in the spirit of the organisation.
    > Correctness should win out.
    >
    > > > C types defined in types.h (Linux) or
    > > > stdint.h (Windows, C99?) are used as if they belong to the C++
    > > > standard namespace.
    > > >
    > > > std::uint8_t instead of uint8_t
    > > > std::uint32_t instead of uint32_t
    > > > ...
    > > >
    > > > I don't think the use of std:: is correct. Nowhere are these types
    > > > explicitly added to the std namespace.

    > >
    > > What do you mean by that?
    > >
    > > > In fact GCC 3.3 fails on them.

    > > So? How is that proof of anything?

    >
    > The release notes for GCC-3.3 discuss types included in std::
    >
    > > > Neither are they among the types defined in the C++ standard language
    > > > support files listed on page 433 in Stroustrup (2nd Ed.)
    > > >
    > > > std::size_t
    > > > std::ptrdiff_t
    > > > std::NULL
    > > >
    > > > defined in <cstddef> are ok. I am wrong about this?

    > >
    > > NULL is a macro, it cannot be defined in a namespace. The Standard
    > > says (17.4.1.1):

    >
    > I stand corrected on NULL.
    >
    > > Now, there is a subclause that says "It is undefined for a C++
    > > program to add declarations or definitions to namespace std [...]"
    > > but it could be argued that types you listed (uint8_t, etc.) are
    > > part of the library implementation and as such belong to std...

    >
    > I would accept that but, as I said above, the types are defined in a
    > file that is not part of the library implementation.
    >
    > > Why don't you ask your development supervisor where they get those
    > > types? They will probably be able to explain why 'std::' is used
    > > there.

    >
    > I have. They have an external file stdint.h defining these types.
    > It is not part of any of the compilers we use. It is hand made to
    > imitate the types defined for C99. Some definitions init it even
    > collide with those in types.h in gcc-3.3. I have brought up this point
    > repeatedly with the leads to no avail. For my own satisfaction I'd
    > like to get to the bottom of this, which is why I posted.


    Andy,

    If you're trying to figure out why such thing has been done, you need
    to keep talking to your colleagues and leads. There must not be "to no
    avail" there. You are simply not supposed to give up. They are YOUR
    colleagues, you're supposed to work TOGETHER, not against each other.

    If you're looking for a justification to pick up a fight with them,
    it is quite possible that you'll lose. They will tell you "we needed
    those C99 types, since they are likely to be included in C++0x, so we
    put them where our compiler can find them, and we put them in the 'std'
    namespace because that's where they'll end up when added to C++0x".
    The header <stdint.h> is standard in C99 and contains the "exact-width
    integer types". A conflict with a GCC's non-standard header <types.h>
    does NOT matter and has to be dealt with in a routine manner, not argued
    about in public.

    Just MHO.

    Victor
     
    Victor Bazarov, Dec 5, 2003
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jeremy Cowles

    STD types vs C++ intrinsic types

    Jeremy Cowles, Aug 18, 2003, in forum: C++
    Replies:
    5
    Views:
    1,942
    Bob Jacobs
    Aug 19, 2003
  2. Peter Jansson
    Replies:
    5
    Views:
    6,439
    Ivan Vecerina
    Mar 17, 2005
  3. Oodini
    Replies:
    1
    Views:
    1,846
    Keith Thompson
    Sep 27, 2005
  4. Vinu
    Replies:
    4
    Views:
    394
    Jim Langston
    Jul 7, 2005
  5. Vinu
    Replies:
    0
    Views:
    376
Loading...

Share This Page