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

Posted on 2004-11-03
Medium Priority
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

Expert Comment

ID: 12490821
you may missed that header file in c program.

include that particular header file and try again

LVL 17

Accepted Solution

rstaveley earned 400 total points
ID: 12490865
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

ID: 12501239
thanks it worked .

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

850 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