473,503 Members | 1,649 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Using extern



Hi,

I would like to know is it possible not to use extern in a program.
For eg I have the following programs

file a.c contains a variable declaration as follows
bool a = TRUE;

I have declared the variable a as extern in the header file a.h as
follows
extern bool a;

In another file b.c which has included the header file a.h I try to
set the variable to FALSE;

I would like to know is there a way of not to use the extern
declaration and still achieve the above scenario.

Thanks in advance

Feb 26 '07 #1
3 8441
Praveen wrote:
I would like to know is it possible not to use extern in a program.
For eg I have the following programs

file a.c contains a variable declaration as follows
bool a = TRUE;
(Where did your boolean type and value come from? If that `bool`
is C99, ten shouldn't `TRUE` be `true`?)
I have declared the variable a as extern in the header file a.h as
follows
extern bool a;

In another file b.c which has included the header file a.h I try to
set the variable to FALSE;
How do you do this? Did you suceeed?
I would like to know is there a way of not to use the extern
declaration and still achieve the above scenario.
Why on Earth would you not want to use the provided mechanism
for allowing a compilation unit to refer to variables defined
in a different unit?

What are you actually trying to /do/?

--
Chris "electric hedgehog" Dollin
The shortcuts are all full of people using them.

Feb 26 '07 #2
Praveen wrote:
Hi,

I would like to know is it possible not to use extern in a program.
For eg I have the following programs

file a.c contains a variable declaration as follows
bool a = TRUE;
If this is the bool defined in C99 then it can only be set to 'true'
or 'false'. All three macros, (yes bool is actually a macro) are
declared in stdbool.h.
I have declared the variable a as extern in the header file a.h as
follows
extern bool a;

In another file b.c which has included the header file a.h I try to
set the variable to FALSE;
Set it to false.
I would like to know is there a way of not to use the extern
declaration and still achieve the above scenario.

Thanks in advance
Why do you want to battle with a language? If you don't like the
mechanisms provided by C, then pick another language.

PS. By receiving a pointer to 'a' from the translation unit where it's
defined, it's possible to do what you want.

Feb 26 '07 #3
On 26 Feb, 11:41, "Praveen" <rpraveen1...@gmail.comwrote:
Hi,

I would like to know is it possible not to use extern in a program.
I assume you want to access data in separate compilation units,
without using extern to share the data.

The answer is "yes" of course. It depends whether you are happy with
the alternatives.

The two approaches which come to mind are either
a) provide a function in the "owning" module which returns the address
of the item you want to access
b) provide more controlled access using accessor functions - one to
get the value of the item, one or more others to set/increment/
decrement/... the value.

Feb 26 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
4709
by: Umesh | last post by:
Hi all I am trying to change the printer(like paper source ,etc) setting in C#. But i am unable to do it. I am not sure how to do it. should i have to use WIN API like Openprinter , getprinter ,...
2
5876
by: rawCoder | last post by:
Hi All, I have a *.cer file, a public key of some one and I want to encrypt some thing using this public key. Can someone point me to a sample code for Encrypting some file using...
3
1954
by: Christopher M. Lusardi | last post by:
Hello, THE PROBLEM ----------- If I compile parts of my program with CC, and C, using extern "C" as appropriate it compiles without any errors, but it does a segmentation fault when I run the...
25
4871
by: John Hanley | last post by:
I have a program where both my main.c and program.c files use the program.h file. So I #include "program.h" in both the .c files. The program.h file has #ifndef PROGRAM_H #define PROGRAM_H...
4
10484
by: Oliver | last post by:
Hello ! I am trying to get the unrar.dll working in C#... it seems that I correctly imported the functions as the first 2 function work without problem (RAROpenArchive & RARGetDLLVersion)......
7
29301
by: Vincent Nguyen | last post by:
Hi, Does anyone know how call Win32 native API GetTokenInformation() by using C#? Any sample code would be helpful. Thanks! Vincent
0
3460
by: Jim dunn | last post by:
HI I am having problems with C# with regards to its compatibility with win32 API methods, I am trying to read from a windows CE comm port using C# and imported methods from coredll.dll, it seems...
2
10503
by: mmmobasher | last post by:
Dear sirs after some googling i found some code to using unrar.dll, but i get runtime error System.NullReferenceException in line iStatus=RARReadHeader(lHandle, ref uHeader); hear is the code ...
0
1367
by: baker_tony | last post by:
Hi, I thought I'd post my notes on how I went about accessing MFC C++ code in my web app after spending a day or more gathering information on how to do it. Please, let me know if you have a...
2
2701
by: =?Utf-8?B?VmljdG9yIExhaQ==?= | last post by:
Hi, I wrote an simple application using VS2005 C#. I am trying to call some functions in my other dll file. This dll is written in EVC for running on Windows CE 5.0. This dll file has the...
0
7198
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.