Click here to Skip to main content
15,900,815 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: how to login????? Pin
With_problem19-Jul-06 21:25
With_problem19-Jul-06 21:25 
QuestionHow to perform opening a file? Pin
ewighell19-Jul-06 14:59
ewighell19-Jul-06 14:59 
AnswerRe: How to perform opening a file? Pin
Stephen Hewitt19-Jul-06 15:11
Stephen Hewitt19-Jul-06 15:11 
GeneralRe: How to perform opening a file? Pin
ewighell19-Jul-06 15:16
ewighell19-Jul-06 15:16 
AnswerRe: How to perform opening a file? Pin
Hamid_RT19-Jul-06 19:11
Hamid_RT19-Jul-06 19:11 
QuestionSystem-Wide WriteProcessMemory Hook Pin
capricious_00119-Jul-06 14:16
capricious_00119-Jul-06 14:16 
AnswerRe: System-Wide WriteProcessMemory Hook Pin
Stephen Hewitt19-Jul-06 15:22
Stephen Hewitt19-Jul-06 15:22 
GeneralPreventing the C++ compiler to optimize [solved] [modified] Pin
Jörgen Sigvardsson19-Jul-06 13:14
Jörgen Sigvardsson19-Jul-06 13:14 
Solution:
Silly me. Originally I had intended to do this stuff in header files, which meant I had to use __declspec(selectany) with these declarations. But at one point, I moved them into the .cpp files, but forgot to remove the __declspec. That directive tells the compiler to keep one reference to the code for the entire link module. If no other code references it, the code is discarded. All I had to do was to remove the directive, and voila! Blush | :O


I have a rather awkward problem with the optimizer in the VS2k3 C++ compiler.
I'm using global objects to initialize a linked list, which I later pick up in the program.

It works sort of like this:
struct Entry {
   Data data;
   Entry* next; 
};
 
extern Entry* g_head = 0;

... 

struct OneOfMyGlobalObjects {
   OneOfMyGlobalObjects() {
      static Entry entry;
      entry.data = ...;
      entry.next = g_head;
      g_head = &entry;
   }
} g_OneOfMyGlobalObjects;
As the g_OneOfMyGlobalObjects variable is never used anywhere in the application, the compiler optimizes it away. Obviously, I don't want that. I figured I could circumvent this by slapping an extern onto the variable, but that didn't help. I went as far as putting a __declspec(dllexport) on it - that did the trick. Although, I don't want to export these objects. It's not the end of the world if I do, but I like tidiness. Smile | :)

Also, I do not fancy the idea of turning off some global optimizer switch, as I like optimization (but just not in these specific instances).

So, is there any magical #pragma or __declspec available?

--
Based on a True Story
Last modified: den 19 juli 2006 18:21:40 --

QuestionFailed to invoke web services in VC++, please help [modified] Pin
Liu Shuai19-Jul-06 11:38
Liu Shuai19-Jul-06 11:38 
AnswerRe: Failed to invoke web services in VC++, please help Pin
kapil_moondra5-Jan-09 1:25
kapil_moondra5-Jan-09 1:25 
QuestionI hate imagelists!! ( drawing with ILD_TRANSPARENT ) [modified] Pin
Maximilien19-Jul-06 11:23
Maximilien19-Jul-06 11:23 
AnswerRe: I hate imagelists!! ( drawing with ILD_TRANSPARENT ) Pin
led mike19-Jul-06 11:40
led mike19-Jul-06 11:40 
GeneralRe: I hate imagelists!! ( drawing with ILD_TRANSPARENT ) Pin
Maximilien19-Jul-06 14:41
Maximilien19-Jul-06 14:41 
AnswerRe: I hate imagelists!! ( drawing with ILD_TRANSPARENT ) Pin
Michael Dunn19-Jul-06 16:15
sitebuilderMichael Dunn19-Jul-06 16:15 
QuestionIs the microphone in use? Pin
Larsson19-Jul-06 10:35
Larsson19-Jul-06 10:35 
QuestionRe: Is the microphone in use? [modified] Pin
Ali Rafiee19-Jul-06 10:52
Ali Rafiee19-Jul-06 10:52 
QuestionHow can I select a node in a treeview Pin
Alex Cutovoi19-Jul-06 9:08
Alex Cutovoi19-Jul-06 9:08 
AnswerRe: How can I select a node in a treeview Pin
Ali Rafiee19-Jul-06 9:21
Ali Rafiee19-Jul-06 9:21 
GeneralRe: How can I select a node in a treeview [modified] Pin
Alex Cutovoi19-Jul-06 11:18
Alex Cutovoi19-Jul-06 11:18 
GeneralRe: How can I select a node in a treeview Pin
Ali Rafiee19-Jul-06 11:23
Ali Rafiee19-Jul-06 11:23 
GeneralRe: How can I select a node in a treeview Pin
Alex Cutovoi20-Jul-06 2:24
Alex Cutovoi20-Jul-06 2:24 
QuestionSerial Communication with a Garmin Device Pin
dinesh_pam19-Jul-06 8:40
dinesh_pam19-Jul-06 8:40 
QuestionRe: Serial Communication with a Garmin Device Pin
cppcook19-Jul-06 9:02
cppcook19-Jul-06 9:02 
AnswerRe: Serial Communication with a Garmin Device Pin
kitty519-Jul-06 9:11
kitty519-Jul-06 9:11 
GeneralRe: Serial Communication with a Garmin Device Pin
dinesh_pam19-Jul-06 9:29
dinesh_pam19-Jul-06 9:29 

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.