Tag: C++

Forward declaration of a structure in C

What do you think of following code? /* * decl.h */ struct junk { int a; }; ———————————————- /* * fwd.c * We have not included the header file decl.h. */ #include struct junk; int main() { struct junk *ptr; printf(“%d”, ptr->a); } You will get compilation error […]

GNU gdb for C++ applications

For C programmers, using GDB for C++ applications could be daunting task. I have learned following lessons: Always pass fully qualified name of a function such as namespace_1::class_1::function1 You can’t put a breakpoint on a template function. jango::IndexInterface<jango::treedata_v1>::toIndex The easiest way is to put the breakpoint on the […]

Pitfall of C array

CODE int main() { int my_array[4] = {11,12,13,14}; int next = 15; printf(“\nSurprise = %d”, my_array[4]); } What should it print? Well, although illegal, the above code does legal things. The array “my_array” has four integers allocated on the stack. The next integer “next” is allocated adjacent to […]