Friday, February 6, 2015

Digest for comp.lang.c++@googlegroups.com - 24 updates in 5 topics

Christopher Pisz <nospam@notanaddress.com>: Feb 06 11:14AM -0600

On 2/6/2015 10:56 AM, Scott Lurndal wrote:
> routine header file requires an int, pass an int. If it requires an
> unsigned long long, pass an unsigned long long. If it requires an
> uint8_t, pass a uint8_t.
 
Ok, so back to where we were from the start. If I never have a
dependency that uses these types, then I should never use them, in your
opinion.
 
In Fibble's opinion, I should _always_ use them.
 
In Ian's opinion, (I think), I should only use them if the operating
system is calling into my code.
 
In at least one other opinion, I should use them if I am going to
perform bitwise operations.
 
In my opinion, I shouldn't be using them at all as long as my target is
Windows x86 and I am not writing hardware drivers, firmware, etc.
 
I think there were several other opinions as well....
Wouter van Ooijen <wouter@voti.nl>: Feb 06 06:25PM +0100

Christopher Pisz schreef op 06-Feb-15 om 6:14 PM:
 
> In my opinion, I shouldn't be using them at all as long as my target is
> Windows x86 and I am not writing hardware drivers, firmware, etc.
 
> I think there were several other opinions as well....
 
Of course, take N experts and get N opinions, + at least 1 extra for
free! Now hire an expert to select the best opinion...
 
Wouter
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 06 05:45PM

On 06/02/2015 16:01, Christopher Pisz wrote:
> // Call OS here
> }
 
> What is it that the posters in this thread are proposing be done?
 
I would probably translate the value of userid the type of which my
algorithm uses (int32_t or whatever) to a value with the type the OS API
expects (int) using some kind of static cast that gives a compiler error
if value truncation would occur with the cast.
 
/Flibble
Christopher Pisz <nospam@notanaddress.com>: Feb 06 12:32PM -0600

On 2/6/2015 11:45 AM, Mr Flibble wrote:
> expects (int) using some kind of static cast that gives a compiler error
> if value truncation would occur with the cast.
 
> /Flibble
 
That's what I thought. I guess it depends on the compiler and settings,
but I've only received warnings. Worse, sometimes the really bad peers
love to disable warnings, or that warning, because they think they know
what they are doing when they don't.
 
If you can guarantee me a compiler error via the previously mentioned
static assertion, then I suppose I can get on board somewhat, but to me
the issue still remains in the form of - when it compiles for one but
not the other, you aren't really getting your cross platform-ed-ness you
were after, because the interface to the OS, which is out of your
control, pooped on it.
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Feb 06 07:13PM

On 06/02/2015 18:32, Christopher Pisz wrote:
> not the other, you aren't really getting your cross platform-ed-ness you
> were after, because the interface to the OS, which is out of your
> control, pooped on it.
 
Nonsense. If the range of values *must be* what int32_t provides and
the OS API doesn't support those range of values to meet your
requirements then you better use a different API, rethink your choice of
OS or change your requirements.
 
/Flibble
Ian Collins <ian-news@hotmail.com>: Feb 07 08:19AM +1300

Christopher Pisz wrote:
>> standard library uses typedef types.
 
> Ok, if I understand you correctly, then you are using these fixed width
> types in code that the operating system calls.
 
No, you completely misunderstood me! My code uses operating system
calls and data structures that use fixed wind types.
 
--
Ian Collins
Christopher Pisz <nospam@notanaddress.com>: Feb 06 03:05PM -0600

On 2/6/2015 1:13 PM, Mr Flibble wrote:
> requirements then you better use a different API, rethink your choice of
> OS or change your requirements.
 
> /Flibble
 
Rethink your OS seems to be a common answer, but a totally unreasonable
one. Who in their right mind would tell $5,000,000 worth of customers,
"sorry guys, we don't do your OS anymore."
Christopher Pisz <nospam@notanaddress.com>: Feb 06 03:08PM -0600

On 2/6/2015 1:19 PM, Ian Collins wrote:
>> types in code that the operating system calls.
 
> No, you completely misunderstood me! My code uses operating system
> calls and data structures that use fixed wind types.
 
Oh ok. Apologies.
You said you work in *nix, right? What's an example of an operating
system call over there and do all of their signatures use those types or
just some?
scott@slp53.sl.home (Scott Lurndal): Feb 06 09:14PM


>Ok, so back to where we were from the start. If I never have a
>dependency that uses these types, then I should never use them, in your
>opinion.
 
That's not what I said. I simply said that you want to match
the argument types to public API's. For usage within the application,
use the appropriate type for the domain of the data.
 
The C++ code I'm currently working on has a lot of this:
 
union GICD_IIDR_t
{
uint32_t u;
struct
{
#if __BYTE_ORDER == __BIG_ENDIAN
uint32_t productid : 8;
uint32_t reserved_20_23 : 4;
uint32_t variant : 4;
uint32_t revision : 4;
uint32_t implementer : 12;
#else
uint32_t implementer : 12;
uint32_t revision : 4;
uint32_t variant : 4;
uint32_t reserved_20_23 : 4;
uint32_t productid : 8;

No comments: