06-26-04 03:10 PM
Anand Subramanian wrote:
> Can someone explain the differences(setup, pre-main()
> setup/initialization) between global variables in a C++ and a C program?
> The global variables I used are uninitialized.
For primitive types, there is none. However, be sure you know and
understand what C++ name mangling is.
> I have a test.o which declares a global int " int xxx;".
Now, that won't work anyways, since declaring something doesn't give you
anything. I'll assume you mean define, as you show in your quote.
> Now I link
> test.o to a FreeBSD kernel module which then tries to access xxx. If
> test.o was compiled from C source the kernel can access the global
> variable (which should be of course its own copy in kernel space and not
> the test.o linked to the user-space application process).
Can you manifest the difference in userspace?
> But if the test.o was generated from C++ source and libstdc++ etc.
> are linked to the kernel module then the kernel freezes upon
> accessing xxx.
I don't think that you want to link libstdc++ into a kernel module, as it
requires a full libc, too, and is a lot of overhead at first.
Anyhow, as in C are no constructors, there is probably no support for
running them for global objects in kernelspace. Also, how about some
details about when exactly the kernel freezes?
Uli
--
http://www.erlenstar.demon.co.uk/unix/
[ Post a follow-up to this message ]
|