473,387 Members | 3,810 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,387 software developers and data experts.

error not caught at link time: should it be?

Hello,

I have two .cpp files. The first one contains:

Foo *foo;

and in the second one contains:

extern Foo foo;

I am using a modified version of gcc
with Makefiles automatically created.
The strange thing is that the tools
go through the link phase without
detecting the error. Isn't it to
be expected that the error be
caught by the linker???

I feel somewhat surprised that
it didn't catch it. I guess
when the linker looks for
external symbols it doesn't
care about matching their
types (eg. pointer versus value).

Thanks!!!

Neil

Jul 27 '05 #1
5 1706
nz******@cs.mun.ca wrote:
I have two .cpp files. The first one contains:

Foo *foo;

and in the second one contains:

extern Foo foo;
The two 'foo' are different. Essentially you have overloading
of the symbol 'foo' here.
I am using a modified version of gcc
with Makefiles automatically created.
Irrelevant here.
The strange thing is that the tools
go through the link phase without
detecting the error. Isn't it to
be expected that the error be
caught by the linker???
Linking is not part of the language specification.
I feel somewhat surprised that
it didn't catch it. I guess
when the linker looks for
external symbols it doesn't
care about matching their
types (eg. pointer versus value).


Since you didn't post _how_ your 'foo' symbols are used, there is
nothing that can be said about it.

V
Jul 27 '05 #2
Victor Bazarov wrote:
nz******@cs.mun.ca wrote:
I have two .cpp files. The first one contains:

Foo *foo;

and in the second one contains:

extern Foo foo;


The two 'foo' are different. Essentially you have overloading
of the symbol 'foo' here.


If the first is at file scope, then it is an ODR violation,
causing undefined behaviour.

A similar situation occurs in the FAQ: one TU contains
char foo[9];
and the other contains
extern char *foo;
which causes undefined behaviour; the latter should have been
extern char foo[];

Jul 27 '05 #3
Old Wolf wrote:
Victor Bazarov wrote:
nz******@cs.mun.ca wrote:
I have two .cpp files. The first one contains:

Foo *foo;

and in the second one contains:

extern Foo foo;
The two 'foo' are different. Essentially you have overloading
of the symbol 'foo' here.

If the first is at file scope, then it is an ODR violation,
causing undefined behaviour.


I am still trying to understand (after an evening of thinking about it)
why it would be an ODR violation. The first statement is a declaration
and a *definition* of a pointer, if it's at the namespace level; it has
static storage duration and as such is zero-initialised. So, it's
a null pointer to Foo. Are you saying it's defined elsewhere again?

The second statement is a declaration of a global object of type Foo
defined elsewhere. If there is an ODR violation, it's the second one,
the object, who isn't defined at all. And it only is an error if the
object is _used_, which we haven't been able to see.
A similar situation occurs in the FAQ: one TU contains
char foo[9];
and the other contains
extern char *foo;
which causes undefined behaviour; the latter should have been
extern char foo[];


Again, only if the name is used.

V
Jul 28 '05 #4
Victor Bazarov schreef:
Linking is not part of the language specification.


Of course it is. It's the part in which Translation Units are
combined. Like any other part of the standard, there is no
implementation detail mandated, but the phase must be there
in some form. In particular, a _linker_ is not part of the
specs, if the compiler can do it. Same as the preprocessor:
doesn't have to be a standalone tool, but the action must be
performed.

HTH,
Michiel Salters

Jul 28 '05 #5
Victor Bazarov wrote:
Old Wolf wrote:
Victor Bazarov wrote:
nz******@cs.mun.ca wrote:

I have two .cpp files. The first one contains:

Foo *foo;

and in the second one contains:

extern Foo foo;

The two 'foo' are different. Essentially you have overloading
of the symbol 'foo' here.


If the first is at file scope, then it is an ODR violation,
causing undefined behaviour.


I am still trying to understand (after an evening of thinking about it)
why it would be an ODR violation. The first statement is a declaration
and a *definition* of a pointer, if it's at the namespace level; it has
static storage duration and as such is zero-initialised. So, it's
a null pointer to Foo. Are you saying it's defined elsewhere again?

The second statement is a declaration of a global object of type Foo
defined elsewhere. If there is an ODR violation, it's the second one,
the object, who isn't defined at all. And it only is an error if the
object is _used_, which we haven't been able to see.


Yes, I think ODR violation would be the wrong term.
I can't seem to find relevant text in the Standard that
deals with this issue though.
A similar situation occurs in the FAQ: one TU contains
char foo[9];
and the other contains
extern char *foo;
which causes undefined behaviour; the latter should have been
extern char foo[];


Again, only if the name is used.


OK.

Jul 28 '05 #6

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

Similar topics

1
by: nzanella | last post by:
Hello, I have two .cpp files. The first one contains: Foo *foo; and in the second one contains: Foo foo;
3
by: deko | last post by:
I have a logging routine that's supposed to silently log errors caught by error handler code on certain functions. The problem is sometimes stuff happens and the error handler can get caught in a...
1
by: gemel | last post by:
I wish to implement error recovery using the Exception mechanism However, I'm not sure I fully appreciate some of the detail in which this works. The code that contains a potential error is...
0
by: Joost | last post by:
Hello all, I am currently developping an intranet website for my company and I encountered a strange thing. I have a global error handler (application_error) in my global.asax file which...
6
by: Matt | last post by:
Can anyone give me a good reason to use BOTH application scope Page_Error and the page scope Page_Error when trapping errors in a web application? Is there any real benefit to using the Page_Error...
5
by: Jimi | last post by:
Hi all, I have a user control which raises an event to the parent page when a person clicks on a link in a datagrid. In the event handler inside the parent page I construct a url to redirect to...
669
by: Xah Lee | last post by:
in March, i posted a essay “What is Expressiveness in a Computer Language”, archived at: http://xahlee.org/perl-python/what_is_expresiveness.html I was informed then that there is a academic...
34
by: Rory Campbell-Lange | last post by:
>>(1.0/10.0) + (2.0/10.0) + (3.0/10.0) 0.60000000000000009 0.59999999999999998 Is using the decimal module the best way around this? (I'm expecting the first sum to match the second). It seem...
2
by: jbanik10 | last post by:
. What errors are caught at compile time vs link time?
16
by: Ed Bitzer | last post by:
Trying to send groups of email with program using System.Net.Mail. I do not clear MailMessage but repeatedly loop changing only the Bcc entries. Works fine if all addresses are valid. As a simple...
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: 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
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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...
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...

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.