473,405 Members | 2,349 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

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 8429
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
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
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...
0
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
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,...
0
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...

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.