G
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?
1. Assume that in your platform (OS + compiler) all pointer types have
the same size. Is there a platform independent way to get at the
"natural signed integer" type for the platform? What I mean by the
natural signed integer type is the primitive signed integer type T
such that
(A) sizeof(T) == sizeof(char*)
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).
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?
A side-question: is there a way to make an assertion like (A) a
*compile* time assertion?
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? And how
unreasonable is this assumption, that is, are there many and widely
used platforms where this assumption is violated?
TIA, with my best regards,
G. Rodrigues
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?
1. Assume that in your platform (OS + compiler) all pointer types have
the same size. Is there a platform independent way to get at the
"natural signed integer" type for the platform? What I mean by the
natural signed integer type is the primitive signed integer type T
such that
(A) sizeof(T) == sizeof(char*)
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).
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?
A side-question: is there a way to make an assertion like (A) a
*compile* time assertion?
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? And how
unreasonable is this assumption, that is, are there many and widely
used platforms where this assumption is violated?
TIA, with my best regards,
G. Rodrigues