473,382 Members | 1,766 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,382 software developers and data experts.

(guaranteed?) default value of an unresolved external

Ok, this is a bit of a quick hack. I have a flag set in another file
(the default value of the flag is 0. In certain files, access to the
flag symbol is not available - I want to know if unresolved symbols are
given the value of 0 ?. Is this compiler specific or part of the C standard?

PS: It is too long winded to explain WHY I need to do this - I just need
to know if it will work reliably - i.e. I can count on an unresolved
external symbol(assumed to be an int) will have the value of 0.

Nov 15 '05 #1
4 1857
What do you mean by access is not available? Is the existence of the
variable unknown to that file or is it in a different process and
access unavailable?

Moreover, won't the compiler throw a fit when you access a non-existent
variable?

Nov 15 '05 #2


Alfonso Morra wrote:
Ok, this is a bit of a quick hack. I have a flag set in another file
(the default value of the flag is 0. In certain files, access to the
flag symbol is not available - I want to know if unresolved symbols are
given the value of 0 ?. Is this compiler specific or part of the C standard?

PS: It is too long winded to explain WHY I need to do this - I just need
to know if it will work reliably - i.e. I can count on an unresolved
external symbol(assumed to be an int) will have the value of 0.


Let me rephrase your question, to be sure we both
mean the same thing by "unresolved symbol." In file a.c
you have

extern int flag;

Usually, your program is built from both a.c and another
file b.c which contains (at file scope, that is, not inside
any function)

int flag = 0; /* or perhaps some other value */

For some reason you decide to build the program from a.c
alone, without b.c to provide the definition of `flag'.
During the build process, you get a message about `flag'
being "unresolved."

If that's your situation, then no: You cannot count on
any particular value for `flag'. You cannot even be sure
that `flag' exists ("unresolved" means that the linker was
not able to find a `flag' anywhere, so its non-existence is
more probable than not). You cannot even be sure that the
build process will produce an executable program; many linkers
will simply fail if unable to satisfy all the references the
program says it requires, some will produce a program-like
file that is somehow marked "not executable" until and unless
you take special action.

From the standpoint of the C language, there are two cases.
If the program ever refers to `flag' in an expression (other
than as the operand of sizeof), there must be exactly one
definition of `flag' in some translation unit ("source file")
that is part of the program. If the program never refers to
`flag' in any expression, it is permissible for `flag' not to
be defined at all. Anything else is simply not a correct C
program.

Since you're concerned about the value of `flag', you
clearly intend to use `flag' in an expression somewhere (that's
the only way you can inspect or change its value). Therefore
the first case applies: Somewhere, `flag' must be defined and
defined exactly once, or else you don't have a program.

--
Er*********@sun.com

Nov 15 '05 #3


Eric Sosman wrote:

Alfonso Morra wrote:
Ok, this is a bit of a quick hack. I have a flag set in another file
(the default value of the flag is 0. In certain files, access to the
flag symbol is not available - I want to know if unresolved symbols are
given the value of 0 ?. Is this compiler specific or part of the C standard?

PS: It is too long winded to explain WHY I need to do this - I just need
to know if it will work reliably - i.e. I can count on an unresolved
external symbol(assumed to be an int) will have the value of 0.

Let me rephrase your question, to be sure we both
mean the same thing by "unresolved symbol." In file a.c
you have

extern int flag;

Usually, your program is built from both a.c and another
file b.c which contains (at file scope, that is, not inside
any function)

int flag = 0; /* or perhaps some other value */

For some reason you decide to build the program from a.c
alone, without b.c to provide the definition of `flag'.
During the build process, you get a message about `flag'
being "unresolved."

If that's your situation, then no: You cannot count on
any particular value for `flag'. You cannot even be sure
that `flag' exists ("unresolved" means that the linker was
not able to find a `flag' anywhere, so its non-existence is
more probable than not). You cannot even be sure that the
build process will produce an executable program; many linkers
will simply fail if unable to satisfy all the references the
program says it requires, some will produce a program-like
file that is somehow marked "not executable" until and unless
you take special action.

From the standpoint of the C language, there are two cases.
If the program ever refers to `flag' in an expression (other
than as the operand of sizeof), there must be exactly one
definition of `flag' in some translation unit ("source file")
that is part of the program. If the program never refers to
`flag' in any expression, it is permissible for `flag' not to
be defined at all. Anything else is simply not a correct C
program.

Since you're concerned about the value of `flag', you
clearly intend to use `flag' in an expression somewhere (that's
the only way you can inspect or change its value). Therefore
the first case applies: Somewhere, `flag' must be defined and
defined exactly once, or else you don't have a program.


OK - I think this answers my question. (I'll have to thinka bout it a
little more to see if the scenario you described fits my situation). Thanks

Nov 15 '05 #4
Alfonso Morra wrote:
Ok, this is a bit of a quick hack. I have a flag set in another file
(the default value of the flag is 0. In certain files, access to the
flag symbol is not available - I want to know if unresolved symbols are
given the value of 0 ?. Is this compiler specific or part of the C
standard?
It is NOT covered by the C standard.
PS: It is too long winded to explain WHY I need to do this - I just need
to know if it will work reliably - i.e. I can count on an unresolved
external symbol(assumed to be an int) will have the value of 0.


No. You can't be certain that the application will run if there are
unresolved symbols. In fact, as far as I am aware, on the systems I use
it either won't link or won't run if there are unresolved symbols.

Any solution to your problem is likely to be highly system specific, so
you will have to ask in a group dedicated to your specific system.
--
Flash Gordon
Living in interesting times.
Although my email address says spam, it is real and I read it.
Nov 15 '05 #5

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

Similar topics

4
by: Rodolphe | last post by:
Hello, I'm French so sorry for my approximate English. When I try to compile a project under Visual C++ 6.0, I've got the following errors : applicap.obj : error LNK2001: unresolved external...
0
by: Ida | last post by:
Hi, I am trying to build an dll with Microsoft Visual C++ but during the linking phase I get linking errors. Script.obj : error LNK2019: unresolved external symbol __imp__PyString_AsString...
1
by: Aravind | last post by:
we have two files: 1. rc4.c (defines one function "create_pin()") 2. MyImpl.c(calling the function "create_pin()"),This implements JNI method. 1.When I am trying to create .dll file with one...
5
by: cschettle | last post by:
I think you need to link with msvcrt.lib ----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==---- http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000...
2
by: f rom | last post by:
----- Forwarded Message ---- From: Josiah Carlson <jcarlson@uci.edu> To: f rom <etaoinbe@yahoo.com>; wxpython-users@lists.wxwidgets.org Sent: Monday, December 4, 2006 10:03:28 PM Subject: Re: ...
2
by: Maydogg6 | last post by:
I need a hand with some stubborn link errors. I'm trying to recreate and old program from 6.0 into .NET, but for some reason when I try to compile I'm getting linking errors for all my function...
6
by: sadegh | last post by:
Hi I have a problem with my program in VC++6 When I compile it, the following errors are listed. I spend a lot of time on the groups.google.com to find its reason, but none of comments could...
0
by: Ryan Gaffuri | last post by:
hlink72@hotmail.com (Eric) wrote in message news:<ab8d8b14.0308220550.54fb5f22@posting.google.com>... LNK1120 is a standard C++ error. you using Visual C++? Means your references a class that...
2
by: =?Utf-8?B?YmFzaA==?= | last post by:
Hello, I am compiling a CPP code using Visual studion .net 2003. I get the following error, despite having windldap.h and wldap32.dll in my include and lib paths. Here is the error. uuid.lib...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.