how to use the variable in c which was declared and assigned in C++

Posted on 2004-11-03
Last Modified: 2010-04-01
  i want to use the one variable which is common through out my VC application. For that what i done is i decalred that variable in one header file and assigned its value in c++ function and i am using it in .c file using extern keyword. but i am not getting the value. what is the best way to use the value in c which should be declared and assigned in C++
  thank you
Question by:vgiridhar
    LVL 2

    Expert Comment

    you may missed that header file in c program.

    include that particular header file and try again

    LVL 17

    Accepted Solution

    Here's your header:

    #ifdef __cplusplus
               int myvar;

    Here's your variable:

    #include "myvar.h"
    int myvar = 123;

    The #ifdef __cplusplus stuff tells C++ modules to expect C linkage for the variable and prevents them from expecting C++ name-mangling.

    Author Comment

    thanks it worked .

    Featured Post

    Gigs: Get Your Project Delivered by an Expert

    Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

    Join & Write a Comment

    C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (…
    Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
    The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
    The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now