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 5 1735 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
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[];
Old Wolf wrote: Victor Bazarov wrote:
nz******@cs.m un.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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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;
|
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 loop. Is there some way
to send a break from VBA code to break out of the loop?
Here's what the error handler code looks like:
Private Function MyFunction
On Error GoTo HandleErr
|
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 included in the Try block.
The Catch block is used to catch this exception. The Finally block
will then execute after the Exception has been handled. My questions
are:
1. If the Exception is caught in the Catch block is this referred to
|
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 should handle all the unhandled exceptions. The strange
thing is, it only catches unhandled exceptions sometimes! One time it
catches the errors and executes the code in the sub and sometimes the
browser just displays a standard error page(asp default...
|
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 if you are already capturing
errors in Application_Error? Also, if you have any links to discussions
about when to use which function it would be helpful.
| |
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
containing information sent from the datagrid.
It all works fine on my local machine but when I send it to the live server
I receive "The thread was being aborted"
Doing some googling suggested that I use
|
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 paper written on this
subject.
On the Expressive Power of Programming Languages, by Matthias
Felleisen, 1990.
http://www.ccs.neu.edu/home/cobbe/pl-seminar-jr/notes/2003-sep-26/expressive-slides.pdf
|
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 anachronistic that decimal takes strings as
input, though.
Help much appreciated;
Rory
|
by: jbanik10 |
last post by:
. What errors are caught at compile time vs link time?
|
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 test I
have attempted to send a valid address, then an invalid address which
my ISP (Comcast) will reject immediately as "Not our customer". I
catch the exception, display and then continue looping to send several
additional valid. The balance...
|
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,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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 presenter, Adolph Dupr who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |