Click here to Skip to main content
15,913,773 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionHow to get camera properties? Pin
Shivarudrayya H4-Aug-08 20:30
Shivarudrayya H4-Aug-08 20:30 
AnswerRe: How to get camera properties? Pin
Mark Salsbery5-Aug-08 6:26
Mark Salsbery5-Aug-08 6:26 
Questiontry-catch dynamic memory cleanup Pin
x87Bliss4-Aug-08 20:21
x87Bliss4-Aug-08 20:21 
AnswerRe: try-catch dynamic memory cleanup Pin
pallaka4-Aug-08 20:39
pallaka4-Aug-08 20:39 
AnswerRe: try-catch dynamic memory cleanup Pin
Cedric Moonen4-Aug-08 20:39
Cedric Moonen4-Aug-08 20:39 
AnswerRe: try-catch dynamic memory cleanup Pin
not_in_use5-Aug-08 8:33
not_in_use5-Aug-08 8:33 
GeneralRe: try-catch dynamic memory cleanup Pin
x87Bliss5-Aug-08 11:25
x87Bliss5-Aug-08 11:25 
GeneralRe: try-catch dynamic memory cleanup Pin
not_in_use5-Aug-08 12:07
not_in_use5-Aug-08 12:07 
AnswerRe: try-catch dynamic memory cleanup Pin
Stephen Hewitt5-Aug-08 14:05
Stephen Hewitt5-Aug-08 14:05 
QuestionHow to install MyApp.exe from custom actions in setup and deployment type project in VS2005 Pin
kapardhi4-Aug-08 20:09
kapardhi4-Aug-08 20:09 
AnswerRe: How to install MyApp.exe from custom actions in setup and deployment type project in VS2005 Pin
_AnsHUMAN_ 4-Aug-08 20:26
_AnsHUMAN_ 4-Aug-08 20:26 
AnswerRe: How to install MyApp.exe from custom actions in setup and deployment type project in VS2005 Pin
KarstenK4-Aug-08 21:19
mveKarstenK4-Aug-08 21:19 
QuestionHow to set Debug Info option in vc++6.0 for command line build? Pin
Super Hornet4-Aug-08 19:48
Super Hornet4-Aug-08 19:48 
QuestionRe: How to set Debug Info option in vc++6.0 for command line build? Pin
Super Hornet4-Aug-08 21:25
Super Hornet4-Aug-08 21:25 
QuestionHow to change Regional Settings(API)? Pin
ritz12344-Aug-08 19:36
ritz12344-Aug-08 19:36 
Questioncreate data base in vc++6 Pin
ani_ikram4-Aug-08 18:27
ani_ikram4-Aug-08 18:27 
AnswerRe: create data base in vc++6 Pin
_AnsHUMAN_ 4-Aug-08 20:00
_AnsHUMAN_ 4-Aug-08 20:00 
GeneralRe: create data base in vc++6 Pin
ani_ikram4-Aug-08 20:56
ani_ikram4-Aug-08 20:56 
GeneralRe: create data base in vc++6 Pin
_AnsHUMAN_ 4-Aug-08 21:46
_AnsHUMAN_ 4-Aug-08 21:46 
QuestionAn exception occurred while trying to run "Shell32.dll,Control_RunDLL ConnectorCpl.cpl Pin
monsieur_jj4-Aug-08 17:23
monsieur_jj4-Aug-08 17:23 
QuestionLINK : fatal error LNK1104: Pin
ani_ikram4-Aug-08 17:23
ani_ikram4-Aug-08 17:23 
AnswerRe: LINK : fatal error LNK1104: Pin
sudhir_Kumar4-Aug-08 19:20
sudhir_Kumar4-Aug-08 19:20 
QuestionClient rectangle not actualized after menu removal Pin
FloatingMarc4-Aug-08 16:40
FloatingMarc4-Aug-08 16:40 
QuestionInlining of consts Pin
not_in_use4-Aug-08 12:17
not_in_use4-Aug-08 12:17 
Hi everyone,

I have a question that may sound a bit strange: What's the most efficient and elegant way to define constants in C++?

I'm in a situation where I have to define constants that might be used in code that needs to be as fast as possible (such as maybe image or sound processing for example). I know the standard way in C++ is like this:

// myFile.h
const float myConst;

// myFile.cpp
const float myConst = 3.5;


Based on my understanding, the initialization must be performed in myFile.cpp since only int constants can be initialized in the header.

The problem is that this looks a lot like the constant won't be inlined but always read from memory (or processor cache of course) when it is accessed. What's worse is that client code will most likely use myFile as part of a DLL/SO, so even if there were the slightest chance that the linker were trained to perform some magic inlining when linking the binary, I'd still be out of luck. Apart from that I need a portable solution that works reliably on Windows, Linux, Mac OS X, and if possible also on SGI Irix, independent of the compiler and linker.

The obvious solution is to just use #define myConst 3.5, but I'd like to avoid that if possible (for obvious reasons).

If I'm right about no inlining being performed, does anyone have any proven workaround for this? All I could come up with was maybe abusing inline functions roughly like so (not tested, just an idea):

#define INLINE_CONST( TYPE, NAME, VALUE ) \
	struct FastConst_T_##NAME { \
		inline operator TYPE { return (VALUE); } \
	} NAME


which then could be used like that:
INLINE_CONST( double, pi, 3.141592653589793238462 ); // Pi from my memory, don't copy without checking

inline double circleArea( radius ) { 
     return r * r * pi;
}


But that's obviously not a very elegant solution. I'm really sorry for the lengthy post, but I can't believe I have to use such hacks to get C++ to inline my constant values. I already tried Google, but I didn't find anything useful.

Thanks in advance,
Peter
AnswerRe: Inlining of consts Pin
sashoalm4-Aug-08 21:53
sashoalm4-Aug-08 21:53 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.