Unix Programming - Re: C and C++ global variable difference(s)

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > June 2004 > Re: C and C++ global variable difference(s)





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Re: C and C++ global variable difference(s)
Ulrich Eckhardt

2004-06-26, 10:10 am

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/
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com