Re: C and C++ global variable difference(s)
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix Programming > Re: C and C++ global variable difference(s)




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

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


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Sponsored Links  




 





   All times are GMT. The time now is 07:21 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register