Issue
I'm getting no output from a simple cout, whereas a printf will always print the number:
std::cout << variableuint8; // prints nothing
printf("%u", variableuint8); // prints the number
I've never run into this behavior before, and while I have a work around I would like to understand it.
Context:
Yay, pointers. So it may be a little more involved than as stated. Here's the context - I don't think it should matter, by the time cout and printf get the info it's dereferenced to a simple unsigned char. This is probably more information than needed to resolve the issue, but I wanted to be complete on the off chance that it was relevant.
typedef unsigned char UInt8;
typedef unsigned short UInt16;
typedef struct{
UInt8 len;
// some other definitions. sizeof(DeviceNotification) <= 8
}DeviceNotification;
UInt8 somerandomdata[8];
DeviceNotification * notification;
notification = (DeviceNotification *) somerandomdata;
std::cout << "Len: (" << notification->len << ")\n";
printf("Len: (%u)\n", notification->len);
The random data is initialized elsewhere. For this output, the first byte in the array is 0x08:
Output:
Len: ()
Len: (8)
Environment
- Development machine:
- OS X 10.6.8
- Compiler LLVM 1.7
- Xcode 3.2.6
- Test machine:
- OS X 10.6.8
DeviceNotification
? – ColdshoulderUInt8 len
) is safe. – Chane