signed-char-array dump in hex digits: printf/cout

C++ code is convoluted. Must cast twice!
static const char tag[] = {'W', 2, 0xFF, 0x80};
// same output from c and c++: 57 02 ff 80
int main(void)
  cout << hex << setfill('0') ;
  for(int i = 0; i< sizeof(tag)/sizeof(char); ++i)
    printf("%02hhx ", tag[i]);
  printf ("\n");

  for(int i = 0; i< sizeof(tag)/sizeof(char); ++i)
    cout << setw(2) << (int)(unsigned char) tag[i] << " ";

Fwd: c++ portability, according to csdoctor

With java, i think we get binary portability in the vast majority of cases. With c++ you usually get good source code portability unless obvious non-portable libraries are used.

———- Forwarded message ———-
From: Qiang Wang
Subject: Re: c++ portability

I think the answer is YES. You have portability problem if you want to move from Windows to UNIX, especially when applications have GUI, hardware driver, network functions. However, for a simple C++
application, you can run on both Windows and UNIX with minimal change after compiling on both systems separately.


On Tue, Aug 24, 2010 at 9:01 AM, Bin TAN (Victor) wrote:
> Hi Friends,
> One potential IV question to verify hands-on c++ experience — Java has a
> big selling point “write once run anywhere”. If you wrote c++ in windows and
> run in unix, did you have portability problems?
> Is there any?

reliably convert Any c++ source to C

Many people ask me “Can you compile a c++ app if you only have a c compiler?”

Some of the foremost experts on c/c++ compiler said on

If you mean “can you convert C++ source to C source, and run the C through a C compiler to get object code”, as a way to run C++ code on a system that has only a C compiler, yes it is possible to implement all of the features of ISO standard C++ by translation to C source code, and except for exception handling this produces object code with efficiency comparable to that of the code generated by a conventional compiler.

For exception handling, it is possible to do an implementation using setjmp/longjmp that is completely conformant, but the code generated will be 5-20% slower than code generated by a true c++ compiler.

Boost Any – barebones cheatsheet

* bite-sized introduction — best is P164 [[beyond c++ standard lib]]. Best 2nd intro is P165.
* Most essential operations on Any are

1) ctors — desposit into safebox
2) any_cast — check out using the “key”

* void pointer — Any is better than void pointers. (It’s good to know that void pointers meet the same basic requirement.)
* shared_ptr — to store pointers in an Any instance, use shared_ptr.
* STL — Any can be used with or without STL containers. First get a firm grip on one of them.

— P164 – without containers
myAny=3.281; // a double
//As shown you can put any object into the variable. To retrieve it, you specify the expected type.
any_cast (myAny);
any_cast (myAny); // would throw exception.

Q: big 3?
Q: can subclass?
Q: name a real use case
Q: this sounds powerful, convenient, too good to be true. What’s the catch? Why not widely used?

##boost modules used ] finance

#1) shared_ptr (+ intrusive_ptr) — I feel more than half  (70%?) of the “finance” boost usage is here. I feel every architect who chooses boost will use shared_ptr
#2) boost thread
# serialization
# boost::ANY

—— other modules used in my systems
* noncopyable — for singletons
** private derivation
** prevents synthesized {op= and copier}, since base class is noncopyable.

* polymorphic_cast
* numeric_cast — mostly int types, also float types

* operators ?
* bind?
* tuple
* regex
* scoped_ptr — as non-copyable [1] stackVar,
[1] different from auto_ptr