On 09/05/2020 18:23,
bol...@nowhere.co.uk wrote:
> On Sat, 9 May 2020 17:57:57 +0200
> David Brown <
david...@hesbynett.no> wrote:
>> On 09/05/2020 17:05,
bol...@nowhere.co.uk wrote:
>>> On Sat, 9 May 2020 16:03:32 +0200
>>> David Brown <
david...@hesbynett.no> wrote:
>>>> On 09/05/2020 12:47,
bol...@nowhere.co.uk wrote:
>>>>> On Sat, 9 May 2020 10:29:34 -0000 (UTC)
>>>>> Juha Nieminen <nos...@thanks.invalid> wrote:
>>>>
>>>> <snip>
>>>>
>>>>>>
>>>>>> using value_type = T;
>>>>>
>>>>> What about in C++98?
>>>>
>>>> What about it? It's a very long time since 1998. Why not use a more
>>>> modern C++ version?
>>>
>>> Portability and curiosity. Allocators existed then so how was it done?
>>
>> Portability should not be an issue - how many people will be using your
>> code without access to at least C++11 ? As for curiosity - often in
>
> Plenty of old systems in companies have old compilers. A company I worked for
> until 2019 was still on C++ 2003. Calls to upgrade fell on deaf ears.
Are you writing code for them? If not, why do you care? C++11 is a
better language than C++03 - it lets you write better code. I can
understand using an older standard if you have to, but not for new code
written by choice.
>
>> If you have an unsigned long, the name of the type in C++ is "unsigned
>> long". There is rarely any advantage of have a typedef that gives you
>> nothing else (as distinct from typedefs like uint64_t) - possibly there
>> are situations where it is convenient for the type name to be a single
>> word. This is not such a case.
>
> Each to their own. unsigned long is long winded, u_long is short and to the
> point and standard on unix.
>
It is not "standard" - common on *nix, but not standard (neither POSIX
not C++ standard). In fact, it is a non-conformity if it is defined as
a result of standard headers (like <stdlib.h>). (gcc and glibc are not
standards conforming by default.) In a brief test on gcc/glibc (various
versions on my Linux system), an include of <stdlib.h> gives the u_long
typedef for different C++ standard but not for the stricter conforming C
standards (it is defined for -std=gnu99 but not for -std=c99). It is
fine to have it defined for C++ -std=gnu++03, but it is a conformity
failure to have it defined for -std=c++03.
It is fine to use short forms when they are useful - that is one of the
reasons why C and C++ have typedefs, macros, include files, and all the
rest. But it is not a good idea to use pointless unnecessary
non-standard abbreviations in code posted for others to see.
If you find you are needing "unsigned long" a lot in your code, and want
to write "u_long" instead, that's fine. (I'd prefer to give a name that
reflects the use or purpose of the type.) I have lots of such cases in
my own code, and I'm sure many others do too. But when I post code here
I use standard types whenever possible.
>> necessarily defined in other systems (C++ is used on far more than just
>> Unix and Windows). And your code does not include <sys/types.h>.
>
> It doesn't need to - its included by stdlib.h
>
>> The appropriate choice of type for printf for a pointer is "%p" and type
>> "void*". If you really want to cast a pointer to an integer type, the
>> type to use is "uintptr_t" - that type /is/ standard, and will be
>> available on any C++ compiler (in theory it requires C++11, in practice
>> any C++ compiler), and it will be the correct size for pointers -
>> something that does not always apply to "unsigned long".
>
> Give somes example architectures when it wouldn't apply?
>
Windows 64 is the obvious case - "long" is 32-bit, while pointers are
64-bit.
And in smaller 8-bit and 16-bit systems, "long" is 32-bit while pointers
are typically 16-bit. (And yes, people use C++ on these.)
Non-portable and system-specific code is fine - that's what most people
write most of the time. /Pointlessly/ non-portable code is, well,
pointless.