* Gonçalo Rodrigues:
> Hi all,
>
> I have a few questions on primitive types that I will divide in two
> main questions. I realize that some of these questions -- especially
> 2. below -- are not directly related to C++ as a language itself, so,
> if there is a better newsgroup to make them would you be so kind and
> please direct me to it?
OK in this newsgroup, as far as I'm concerned.
Generally, just consider whether your posting would be accepted in the clean
but slow version of this group, [comp.lang.c++.moderated].
You may consult the moderation policy of that group, at
<url: http://www.gotw.ca/resources/clcm.htm>, see the section "Accepting or
Rejecting Articles".
> 1. Assume that in your platform (OS + compiler) all pointer types have
> the same size.
All pointer types do not necessarily have the same size.
§3.9.2/4 "A void* shall be able to hold any object pointer".
A function is not an object.
> Is there a platform independent way to get at the
> "natural signed integer" type for the platform?
Be aware that "natural signed integer" means 'int' in C and C++, but apart
from that, using your definition below, the answer is no.
> What I mean by the
> natural signed integer type is the primitive signed integer type T
> such that
>
> (A) sizeof(T) == sizeof(char*)
There is no requirement that such a type exists!

But in practice it
will exist. However, it need not be a standard C++ type.
> In my code, what I have for now is a simple typedef
>
> typedef int integer
>
> in a header file that is include-d everywhere else and then use
> integer as the integral type. This is good enough for the platform I
> am using to test my code (Windows, btw).
That will not work for 64-bit Windows.
> What are some examples of plarforms where the two assumptions above
> (every pointer type has the same size and int is the natural signed
> integral type for the platform) are violated?
One example is Windows using Microsoft's compiler. 'int' is not able to
represent even simple data pointers in 64-bit Windows. I'm not aware of an
example where function pointers are larger than void*, but that is allowed.
> A side-question: is there a way to make an assertion like (A) a
> *compile* time assertion?
Yes, just use a compile time assertion.

E.g. the one in Boost.
> 2. The instances of classes in my project are heap-allocated and use a
> reference count to keep track of them. They are then managed via a
> smart pointer template. For now, there is no possibility of
> circularity so reference count is good enough. But it just dawned on
> me that the simple operation
>
> (B) this->count++;
>
> may not be atomic, which means that these objects are not thread-safe.
> Is there anyway to find out if (B) above is atomic?
Platform-dependent.
> And how
> unreasonable is this assumption, that is, are there many and widely
> used platforms where this assumption is violated?
I think Windows is, again, an example. A platform may provide special
atomic increment and decrement operations.
--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?