"static inline" function has global visibility with no linker warning

I had 2 units with functions with the same name but different return 
types.  In one unit the function was declared "static inline".  The 
linker ended up using the "static inline" function in all cases.  There 
was no linker warning that there were duplicate names.

Here is a test case (as CB2009 console application, but the original 
problem was in a VCL forms app in CB2007).  Set breakpoint at the return 
of main.  find_time(i) should return 30, but returns 20.  (Note: The 
order of linking may affect which version of round is used.)  Tracing 
through the code shows that the File2 version of round is called from 
File3.  If round is static (no inline) the program works as expected.

File1.cpp:
#include <tchar.h>
//---------------------------------------------------------------------------
extern void dummy ();
extern unsigned find_index (double time);
extern double find_time (unsigned index);

#pragma argsused
int _tmain(int argc, _TCHAR* argv[])
{
	dummy(); // call to ensure dummy is linked in
	unsigned i = find_index(30);
	double t = find_time(i);  // should be 30
	return 0;
}
//---------------------------------------------------------------------------

File2.cpp:
#include <math.h>
inline static int round (double z) { return floor (z + 0.5); }
// static int round (double z) { return floor (z + 0.5); } // works

void dummy ()
{
	double x = 1;
	double y = 2;
	int xx = round(x);
	int yy = round(y);
}

File3.cpp:
extern double round(double z); // forward declaration

/* Returns index into adc_data corresponding to time. */
unsigned find_index (double time)
{
	unsigned	remains;
	unsigned	baseoffset = 1480;
	double		offset = 20;
	double		baserate = 0.5;

	remains = round ((time - offset) / baserate);
	return (baseoffset + remains);
}

/* returns time corresponding to index into adc_data */
double find_time (unsigned index)
{
	unsigned	remains;
	unsigned	baseoffset = 1480;
	double		offset  = 20;
	double		baserate = 0.5;

	remains = index - baseoffset;
	return (offset + remains * baserate);
}

#include <math.h>
double round (double x)
{
     return (floor (x + 0.5));
}
0
Eliot
1/3/2009 4:35:07 PM
embarcadero.cppbuilder.cpp 2803 articles. 0 followers. Follow

0 Replies
493 Views

Similar Articles

[PageSpeed] 13

Reply:

Similar Artilces:

superreview granted: [Bug 270342] In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" : [
David Bienvenu <bienvenu@nventure.com> has granted Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 270342: In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" https://bugzilla.mozilla.org/show_bug.cgi?id=270342 Attachment 168078: (Av2b) <threadPane.js> https://bugzilla.mozilla.org/attachment.cgi?id=168078&action=edit ...

superreview cancelled: [Bug 270342] In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" :
neil@parkwaycc.co.uk <neil.parkwaycc.co.uk@myrealbox.com> has cancelled Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 270342: In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" https://bugzilla.mozilla.org/show_bug.cgi?id=270342 Attachment 166201: (Av1) <threadPane.js> https://bugzilla.mozilla.org/attachment.cgi?id=166201&action=edit ------- Additional Comments from neil@parkwaycc.co.uk <neil.parkw...

superreview requested: [Bug 270342] In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" : #2
Serge GAUTHERIE <gautheri@noos.fr> has asked David Bienvenu <bienvenu@nventure.com> for superreview: Bug 270342: In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" https://bugzilla.mozilla.org/show_bug.cgi?id=270342 Attachment 166201: (Av1) <threadPane.js> https://bugzilla.mozilla.org/attachment.cgi?id=166201&action=edit ...

superreview requested: [Bug 270342] In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" : #3
Serge GAUTHERIE <gautheri@noos.fr> has asked David Bienvenu <bienvenu@nventure.com> for superreview: Bug 270342: In <threadPane.js>, "Warning: function MsgSortThreadPane does not always return a value" and "Warning: function MsgToggleThreaded does not always return a value" https://bugzilla.mozilla.org/show_bug.cgi?id=270342 Attachment 168078: (Av2b) <threadPane.js> https://bugzilla.mozilla.org/attachment.cgi?id=168078&action=edit ...

superreview cancelled: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 151481] (Cv1) <nsMsgBodyHandler.cpp>
Serge GAUTHERIE <gautheri@noos.fr> has cancelled Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 151481: (Cv1) <nsMsgBodyHandler.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=151481&action=edit ...

superreview granted: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 156855] (Cv2) <nsMsgBodyHandler.cpp>
Dan Mosedale <dmose@mozilla.org> has granted Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 156855: (Cv2) <nsMsgBodyHandler.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=156855&action=edit ------- Additional Comments from Dan Mosedale <dmose@mozilla.org> sr=dmose ...

superreview requested: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 151481] (Cv1) <nsMsgBodyHandler.cpp>
Serge GAUTHERIE <gautheri@noos.fr> has asked David Bienvenu <bienvenu@nventure.com> for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 151481: (Cv1) <nsMsgBodyHandler.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=151481&action=edit ------- Additional Comments from Serge GAUTHERIE <gautheri@noos.fr> Matthias: Could you try to compile, and possibly test, this patch ? Thanks. Note {{ GetI...

superreview requested: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 137748] (Av1b) <nsMacMain.cpp>
Serge GAUTHERIE <gautheri@noos.fr> has asked Brian Ryner <bryner@brianryner.com> for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 137748: (Av1b) <nsMacMain.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=137748&action=edit ...

superreview granted: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 137748] (Av1b) <nsMacMain.cpp>
Brian Ryner <bryner@brianryner.com> has granted Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 137748: (Av1b) <nsMacMain.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=137748&action=edit ------- Additional Comments from Brian Ryner <bryner@brianryner.com> The explicit |(void)| cast should not be needed. sr=bryner if you remove that. ...

superreview requested: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 151802] (Dv1) <nsViewManager.cpp>
Serge GAUTHERIE <gautheri@noos.fr> has asked David Baron <dbaron@dbaron.org> for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 151802: (Dv1) <nsViewManager.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=151802&action=edit ------- Additional Comments from Serge GAUTHERIE <gautheri@noos.fr> Matthias: Could you try to compile, and possibly test, this patch ? Thanks. ...

superreview granted: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 141227] (Av1c) <nsMacMain.cpp>
Serge GAUTHERIE <gautheri@noos.fr> has granted Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 141227: (Av1c) <nsMacMain.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=141227&action=edit ------- Additional Comments from Serge GAUTHERIE <gautheri@noos.fr> Keeping { (Av1b) <nsMacMain.cpp> patch 2003-12-20 05:33 PST pinkerton: r...

superreview requested: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 156855] (Cv2) <nsMsgBodyHandler.cpp>
Serge GAUTHERIE <gautheri@noos.fr> has asked Dan Mosedale <dmose@mozilla.org> for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 156855: (Cv2) <nsMsgBodyHandler.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=156855&action=edit ------- Additional Comments from Serge GAUTHERIE <gautheri@noos.fr> Keeping {{ (Cv1) <nsMsgBodyHandler.cpp> patch 2004-06-22 15:20 PDT neil.parkwaycc.co.uk...

superreview granted: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 151802] (Dv1) <nsViewManager.cpp>
David Baron <dbaron@dbaron.org> has granted Serge GAUTHERIE <gautheri@noos.fr>'s request for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 151802: (Dv1) <nsViewManager.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=151802&action=edit ...

superreview requested: [Bug 228780] Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") : [Attachment 151481] (Cv1) <nsMsgBodyHandler.cpp> #2
Serge GAUTHERIE <gautheri@noos.fr> has asked Dan Mosedale <dmose@mozilla.org> for superreview: Bug 228780: Fix all "Unused variable '[...]'" 'Build Warnings' (Part 2/2: "with function call") http://bugzilla.mozilla.org/show_bug.cgi?id=228780 Attachment 151481: (Cv1) <nsMsgBodyHandler.cpp> http://bugzilla.mozilla.org/attachment.cgi?id=151481&action=edit ------- Additional Comments from Serge GAUTHERIE <gautheri@noos.fr> No super-review from <bienvenu@nventure.com> since "2004-06-22" :-( ...

Web resources about - "static inline" function has global visibility with no linker warning - embarcadero.cppbuilder.cpp

Resources last updated: 12/15/2015 6:23:38 PM