Click here to Skip to main content
15,887,027 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
QuestionRe: volatile issue - repost Pin
Richard MacCutchan22-May-18 8:26
mveRichard MacCutchan22-May-18 8:26 
AnswerRe: volatile issue - repost Pin
CPallini22-May-18 10:11
mveCPallini22-May-18 10:11 
AnswerRe: volatile issue - repost Pin
leon de boer22-May-18 19:12
leon de boer22-May-18 19:12 
GeneralRe: volatile issue - repost Pin
CPallini22-May-18 21:39
mveCPallini22-May-18 21:39 
QuestionRe: volatile issue - repost Pin
CPallini22-May-18 10:11
mveCPallini22-May-18 10:11 
AnswerRe: volatile issue - repost Pin
Vaclav_22-May-18 11:54
Vaclav_22-May-18 11:54 
GeneralRe: volatile issue - repost Pin
leon de boer22-May-18 15:44
leon de boer22-May-18 15:44 
GeneralRe: volatile issue - repost Pin
Vaclav_22-May-18 17:44
Vaclav_22-May-18 17:44 
OK, it's late but here is the latest.

This code with result declared as volatile PRINTS the correct value of "result".
However "cout" outputs value of 1 - that is ONE.

After removing "volatile" from declaration of result - cout will output 4.

I'll let you gentlemen decide where is my problem , it the meantime I am initializing the pointer to zero and will be checking for absence of zero and hoping computer is adding the values correctly.

BTW the correct additions of both values was never my concern , hence I did not care about the uninitialized value of "base" and was using "int" to test.
.



<pre lang="c++">/*
uint32_t *base = 0;
uint32_t offset = 1;
volatile uint32_t *result;
result = base + offset;
printf("Volatile result pointer = %p\n", result);

*/

uint32_t *base = 0;
uint32_t offset = 1;
volatile uint32_t *result;
result = base + offset;

cout << "base " << base << '\n';
cout << "offset " << offset << '\n';

THIS LINE IS AN UNRESOLVED ISSUE
OUTPUT IS CORRECT WHEN NO VOLATILE KEYWORD IS USED
result = 1 WHEN VOLATILE IS USED

cout << "result " << result << '\n';


this always prints correct value

printf("Volatile result pointer = %p\n", result);

</pre>

PS
ill try "bad compiler" in the morning.
GeneralRe: volatile issue - repost Pin
leon de boer22-May-18 18:13
leon de boer22-May-18 18:13 
GeneralRe: volatile issue - repost SOLVED Pin
Vaclav_23-May-18 3:17
Vaclav_23-May-18 3:17 
QuestionRe: volatile issue - repost SOLVED Pin
CPallini23-May-18 3:28
mveCPallini23-May-18 3:28 
GeneralRe: volatile issue - repost SOLVED Pin
Richard MacCutchan23-May-18 3:32
mveRichard MacCutchan23-May-18 3:32 
GeneralRe: volatile issue - repost SOLVED Pin
Peter_in_278023-May-18 3:44
professionalPeter_in_278023-May-18 3:44 
GeneralRe: volatile issue - repost SOLVED Pin
leon de boer23-May-18 6:55
leon de boer23-May-18 6:55 
GeneralRe: volatile issue - repost SOLVED Pin
Vaclav_24-May-18 5:53
Vaclav_24-May-18 5:53 
GeneralRe: volatile issue - repost SOLVED Pin
supercat931-May-18 12:48
supercat931-May-18 12:48 
GeneralRe: volatile issue - repost SOLVED Pin
leon de boer4-Jun-18 21:05
leon de boer4-Jun-18 21:05 
GeneralRe: volatile issue - repost SOLVED Pin
supercat98-Jun-18 10:31
supercat98-Jun-18 10:31 
QuestionReturn a local 2d Array Pin
kinderu18-May-18 8:59
kinderu18-May-18 8:59 
AnswerRe: Return a local 2d Array Pin
Richard MacCutchan18-May-18 9:13
mveRichard MacCutchan18-May-18 9:13 
GeneralRe: Return a local 2d Array Pin
kinderu18-May-18 9:45
kinderu18-May-18 9:45 
GeneralRe: Return a local 2d Array Pin
leon de boer18-May-18 16:34
leon de boer18-May-18 16:34 
GeneralRe: Return a local 2d Array Pin
Richard MacCutchan18-May-18 20:46
mveRichard MacCutchan18-May-18 20:46 
AnswerRe: Return a local 2d Array Pin
jfbode102930-May-18 4:46
jfbode102930-May-18 4:46 
QuestionCan someone show me an example of including a DLL or function in a C program ? Pin
m3mb3r17-May-18 10:41
m3mb3r17-May-18 10:41 

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.