int64_t vs long long

Ξ February 21st, 2010 | → 0 Comments |
Programming |, , , , |

This last monday morning, a colleague enters in my office and asked for my… how should I put it… let’s say technical advise.

This time the discussion was about using int64_t and double in some deprecated code involving type casts and trunc of doubles into integers.
This discussing made me research a bit about C and C++ data types regarding integers, since somewhere along the way I listened to something like “I was told to use int64_t because long long is architecture dependent”. It struck deep.

Let’s start with some simple clarifications:

  •  int, or signed int, type must contain at least 16 bits (since the standard mandates that in must support values ranging from -32,767 to +32,767)
  •  long, or long int or signed long int, type must contain at least 32 bits (since the standard mandates that in must support values ranging from -2,147,483,647 to 2,147,483,647)
  •  long long, or long long int or signed long long int, type must contain at least 64 bits (since the standard mandates that in must support values ranging from -9,223,372,036,854,775,807 to 9,223,372,036,854,775,807). Note that this data type was first defined by C99 standard.

Regarding int64_t, as it seems, C99 standard defines a header files called stdint.h as part of the C standard library, that contains portable definitions for integer types. Portable in the sense of explicitly stating the number of bits used to represent a given integer. The definitions are in the form of intN_t and uintN_t, for N bit integers and unsigned integers, respectively. This way the programmer can ensure that, whatever the wordsize used by the processor, the right range of values can be represented. The standard garantees that the widths for these types must be ≥ N.

However well supported by modern compilers, take notice that stdint.h is not officially in the latest C++ standard (know by C++03).

Looking again at the statement that aroused my curiosity, what is the relation between int64_t and long long?
Well, they represent the same thing in most architectures! Both int64_t and long long first got defined by C99 standard, but int64_t definition ensures that 64 bits are used for represent the integer value while with long long at least 64 bits must be used.

For example, some architectures represent long and int with the same number of bits (32 bits). The standard only requires at least N bits. :-)

 

Define: Single Point of Failure

Ξ February 21st, 2010 | → 0 Comments |
Definition |, |

According to Google Analytics, “Single Point of Failure” is one of the expressions that brings more people to this humble place. I guess people searching Google for this expression would like to see the actual definition, and not only the title of the blog.

So, after some investigation, here it is! And the definition of Single Point of Failure is…

Single Point of Failure refers to a specific part of a system, that in case of failure can cause major disruption to the normal work-flow. If you are talking about a computer network, think about the centralized Internet access point of the database server But you can also thing about you hard-disk system, if you are not using a RAID system.
Once the single point of failure goes down, there’s major loss of functionality possibly the complete halt of the system. One simple technique that can be used to mitigate the existence of a single point of failure. Redundancy is done by having several instances critical components working in cooperation avoids the dependence on one unique piece of equipment. It is important to consider implementing distinct approach for the redundant equipment, as this ensure there is no relation between failures of each independent piece of equipment.

For instance in your home, if you’re like me, a modem breakdown or a torn phone line can totally mean the end-of-times (knock on wood). I’m talking about the sky turning black and thunderstorms breaking havoc. The last time it happened I was almost three weeks without Internet, phone and TV. I mean, all that was left to do in the evening was to read. :-) Total misery.

Now, for all of you not interested in this subject, just wait for people to start coming here looking for… You tell me!

 

On the nightstand...


    The Art of Agile Development


    Beautiful Architecture


    Modern C++ Design


    Large Scale C++ Software Design

Personal

Friends


Interesting


Shared Readings