I read a question on the difference between:
const char*
and
const char[]
where as for a while, I though arrays were just syntactic sugar for pointers. But something is bugging me, I have a pice of code similar to the following:
namespace SomeNamespace {
const char* str = { 'b', 'l', 'a', 'h' };
}
I get, error: scaler object 'str' requires one element in initializer. So, I tried this:
namespace SomeNamespace {
const char str[] = { 'b', 'l', 'a', 'h' };
}
It worked, at first I thought this may have to do with the fact that an extra operation is applied when it is a const char*, and GCC is never a fan of operations being performed outside a function (which is bad practice anyway), but the error does not seem to suggest so. However in:
void Func() {
const char* str = { 'b', 'l', 'a', 'h' };
}
It compiles just fine as expected. Does anyone have any idea why this is so?
x86_64/i686-nacl-gcc 4(.1.4?) pepper 19 tool - chain (basically GCC).