473,756 Members | 2,117 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

global variable name conflict with standard header

Hello all
I would like to give a certain name to a certain global variable. Unfortunately,
this name is already used in math.h for a mathematical function. Worse, I do
need to use maths library and therefore have to include math.h. Thus my compiler
reports conflicting declarations of the same name.
Does anyone know any reasonably elegant way to resolve this conflict? I
understand that I can give up and choose another name, but somehow not happy
with that.
Any advice would be much appreciated!
- V.

Nov 14 '05
16 3599
Emmanuel Delahaye <em***@YOURBRAn oos.fr> wrote:
Richard Bos wrote on 11/08/04 :
(BTW, it's not a C question)


Yes, it is: you cannot have two conflicting declarations of the same
identifier, hence the problem. Of course, the answer is "don't do that,
then", but that doesn't make the question off-topic.


Ok. I meant that it's not specific to C.


Not completely, but it's not a completely general problem, either. Many
languages have ways to specify the namespace of an identifier, allowing
you to do what the OP wants to do. C does not. It's true that C isn't
the only language which doesn't; but that alone doesn't make it
off-topic.

Richard
Nov 14 '05 #11
"Arthur J. O'Dwyer" <aj*@nospam.and rew.cmu.edu> wrote:
On Wed, 11 Aug 2004, CBFalconer wrote:
place. For example, if you #include <stdlib.h> and write your own
routine malloc(), the library routine for malloc may not get
loaded. However the realloc() routine may well call the original
malloc, and if rerouted its assumptions are no longer valid. All
of these may be called behind your back in the initialization
code.


Amplification: It's not just the library-linkage problem. We
have sentences in the Standard that say explicitly things like

[#3] The implementation shall behave as if no library
function calls the rand function.

and yet it's /still/ UB to define 'extern int rand;'. This may be
for the benefit of dumb optimizers who can now inline any standard
library routine they like, without checking symbol tables or whatnot.


Not just that. It would be allowed, for example, to
- save the state of rand();
- call rand() to get a random number;
- restore the previous state.
If the programmer can replace rand(), this is no longer possible.

Of course, this is hardly likely to be useful with rand() itself; but it
is a possibility.

Richard
Nov 14 '05 #12
Richard Bos wrote:
.... snip ...
Not completely, but it's not a completely general problem, either.
Many languages have ways to specify the namespace of an identifier,
allowing you to do what the OP wants to do. C does not. It's true
that C isn't the only language which doesn't; but that alone
doesn't make it off-topic.


Yes, C does have namespaces. To grossly simplify, anything
starting with a '_' is in system space, and most ordinary
identifiers are in user space. They just aren't named
namespaces. struct and enum tags are another area.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
Nov 14 '05 #13

"pete" <pf*****@mindsp ring.com> wrote
The first question that comes to my mind is,
is that certain name, a reserved identifier?

(In other words, "Which name?")

It would be a sin to tell you.
Nov 14 '05 #14
Malcolm wrote:

"pete" <pf*****@mindsp ring.com> wrote
The first question that comes to my mind is,
is that certain name, a reserved identifier?

(In other words, "Which name?")

It would be a sin to tell you.


Does it start with an underscore ?
Nov 14 '05 #15
Malcolm wrote:
"pete" <pf*****@mindsp ring.com> wrote
The first question that comes to my mind is,
is that certain name, a reserved identifier?

(In other words, "Which name?")


It would be a sin to tell you.


And cos we'd have to tan your floor and say pow!
Nov 14 '05 #16
On Thu, 12 Aug 2004 19:15:56 +0100, "Malcolm"
<ma*****@55bank .freeserve.co.u k> wrote:

"pete" <pf*****@mindsp ring.com> wrote
The first question that comes to my mind is,
is that certain name, a reserved identifier?

(In other words, "Which name?")

It would be a sin to tell you.

Just be cos?

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #17

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

Similar topics

10
17879
by: Matt | last post by:
Greetings, What are people's thoughts on global variables in C++? Why are we taught not to use them in programming? Is it true that if you are running two copies of the C program one copy can overwrite another copies global variable? I know that you could overwrite a value in a global variable from a function, but you could also do that if you pass the variable in and then out again... so how is that any different?
12
2001
by: Santiago de Compostela | last post by:
Hi The following program doesn't compile on MS VC++ or Bloodshed Dev-C++ #include <iostream> int strlen(const char *in) {
4
7134
by: Dan Elliott | last post by:
Hello, Converting from a working C program to C++, I run into the following error: I have a header: (header.h) namespace shared{ ... struct X{ ...
3
6448
by: Eric Lilja | last post by:
Hello, I have a few global variables in my program. One of them holds the name of the application and it's defined in a header file globals.hpp (and the point of definition also happen to be the point of declaration of this variable, correct?): static const char * g_application_name = "Tiny, class-based MDI Example"; In another source file, I'm including the header globals.hpp and I'm using the variable g_application_name. I do,...
5
3493
by: j | last post by:
Anyone here feel that "global variables" is misleading for variables whose scope is file scope? "global" seems to imply global visibility, while this isn't true for variables whose scope is file scope. If you have a variable whose scope is file scope in another translation unit, you have to provide a local declaration to access that variable from the other translation unit. Also, I don't see "global variable" used once in the standard....
18
2947
by: robert | last post by:
Using global variables in Python often raises chaos. Other languages use a clear prefix for globals. * you forget to declare a global * or you declare a global too much or in conflict * you have a local identical variable name and want to save/load it to/from the global with same name * while you add code, the definition of globals moves more and more apart from their use cases -> weirdness; programmers thinking is fragmented * using...
1
29378
weaknessforcats
by: weaknessforcats | last post by:
C++: The Case Against Global Variables Summary This article explores the negative ramifications of using global variables. The use of global variables is such a problem that C++ architects have called it polluting the global namespace. This article explores what happens when the global namespace becomes polluted and how to avoid this condition. The opinions expressed in this article are those of the author alone although many have...
112
5468
by: istillshine | last post by:
When I control if I print messages, I usually use a global variable "int silent". When I set "-silent" flag in my command line parameters, I set silent = 1 in my main.c. I have many functions that may print some messages. foo(...) { if (!silent)
1
9922
by: Jaco Naude | last post by:
Hi, I'm using a static library in my application which links fine except for a few global variables. The static library only contains a bunch of .cpp and .h files and the global variables are defined as follows: extern unsigned mgl_numg, mgl_cur; extern float mgl_fact; extern long mgl_gen_fnt; extern short mgl_buf_fnt;
0
9462
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9287
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9722
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8723
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6542
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5155
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5318
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3369
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2677
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.