Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Curious phenomenon about the std::prefix and integer aliases

16 views
Skip to first unread message

Juha Nieminen

unread,
Aug 11, 2022, 4:18:11 AM8/11/22
to
I have noticed quite many times a rather curious phenomenon when it
comes to using the 'std::' prefix and the type aliases in <cstdint>:

There's a lot of C++ programmers who will use the 'std::' prefix
for all standard library names (including those that come from the
C standard library)... except for the type aliases in <cstdint>,
such as int32_t, uint64_t, size_t, etc. They do this extremely
consistently: The prefix with every other standard library name,
never with the standard library integer type aliases.

This phenomenon seems to be strangely common. I wonder why.

(AFAIK the standard does not guarantee that the unprefixed names
will work unless you #include <stdint.h>. They never do that,
however. And even those who do... well, I still can't really
comprehend why they meticulously use the prefix with everything
except those type aliases.)

Gawr Gura

unread,
Aug 11, 2022, 5:19:47 AM8/11/22
to
What's to wonder about? People write software based on their
understanding of conventions and not a pedantic commitment to the
wording of the standard. Apparently, unlike various other names found in
the standard library, the standard integer types don't present enough
surprises when used in this way for people to change what they're doing.

Personally, I always use the qualified name (e.g., std::int32_t) or an
alias. I'm partial to defining i8, i16, i32, i64, and so on. What's your
preference?

Ben Bacarisse

unread,
Aug 11, 2022, 11:28:28 AM8/11/22
to
Juha Nieminen <nos...@thanks.invalid> writes:

> I have noticed quite many times a rather curious phenomenon when it
> comes to using the 'std::' prefix and the type aliases in <cstdint>:
>
> There's a lot of C++ programmers who will use the 'std::' prefix
> for all standard library names (including those that come from the
> C standard library)... except for the type aliases in <cstdint>,
> such as int32_t, uint64_t, size_t, etc. They do this extremely
> consistently: The prefix with every other standard library name,
> never with the standard library integer type aliases.
>
> This phenomenon seems to be strangely common. I wonder why.

Maybe they think of these types (or maybe they may want to suggest that
these types) are more like the standard types int, long an so on?

Maybe they are not sure that the C standard does not give permission for
these names to be macros? (It doesn't.)

--
Ben.

Juha Nieminen

unread,
Aug 11, 2022, 4:14:34 PM8/11/22
to
Ben Bacarisse <ben.u...@bsb.me.uk> wrote:
> Maybe they think of these types (or maybe they may want to suggest that
> these types) are more like the standard types int, long an so on?

I myself got bitten by that... but in reverse.

After all, wchar_t looks exactly like those other type aliases.
Yet it's not.
0 new messages