Monday, April 25, 2011

C++ for Java programmers - part 1

1. You need a constructor, and it needs to initialize every field

When in C, I had this nice circular buffer structure. It lived in the .bss (zeroed out) data section, which was great, because all the pointers were supposed to start at zero.

When this was converted to a C++ class, it became obvious that the fields were uninitialized, and not zeroed out.

I actually suspect that it's not C++, but -fdata-sections. This breaks out every global variable into its own section. Zeroed variables are in sections called .bss._Zmangled_variable_name . This is great for removing dead code, but means that the startup code is not smart enough to do all the .bss.* sections

But: with a constructor which zeroes all the fields, it works.

No comments:

Post a Comment