Click here to Skip to main content
16,011,170 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
GeneralRe: SnapShot Pin
Liger_Zero_X7-Jul-04 20:18
Liger_Zero_X7-Jul-04 20:18 
GeneralRe: SnapShot Pin
erkanina7-Jul-04 22:48
erkanina7-Jul-04 22:48 
GeneralRe: SnapShot Pin
Liger_Zero_X8-Jul-04 0:49
Liger_Zero_X8-Jul-04 0:49 
GeneralRe: SnapShot Pin
ThatsAlok8-Jul-04 1:30
ThatsAlok8-Jul-04 1:30 
GeneralRe: SnapShot Pin
Liger_Zero_X8-Jul-04 16:59
Liger_Zero_X8-Jul-04 16:59 
GeneralRe: SnapShot Pin
Liger_Zero_X8-Jul-04 21:21
Liger_Zero_X8-Jul-04 21:21 
GeneralRe: SnapShot Pin
Liger_Zero_X8-Jul-04 22:47
Liger_Zero_X8-Jul-04 22:47 
GeneralQuestions on the keyword "register" in C & C++ Pin
Link26007-Jul-04 15:56
Link26007-Jul-04 15:56 
Okay, first of all, please look at the following codes. The first block of code was written in C whereas the second
block of code was written in C++.

Both of the codes have the same purpose:
declare an integer variable using register keyword, then print its memoryaddress using & operator. Since the register in CPU does not have a memory address, so if the integer is really put in the CPU's register, it won't print its address, because there is no address.

Note: Both versions were built in VS.Net 03.
--------------------------------------------------

// main.c
<br />
#include <stdio.h><br />
<br />
int main(void)<br />
{<br />
   int register a = 10;<br />
   printf("%d\n", &a);<br />
<br />
   return 0;<br />
}<br />

result: error C2103: '&' on register variable
--------------------------------------------------

// main.cpp
<br />
#include <iostream><br />
<br />
int main()<br />
{ <br />
   int register a = 10; <br />
   std::cout << &a << std::endl;<br />
<br />
   return 0;<br />
}<br />

result : 0012FED4 (successfully built & run)
--------------------------------------------------

Questions:

1.)
The first block of code seemed worked, because it stays an error. However, as I tried to do the same thing in C++, it runs and printed a memory address!!

So, the integer is not actually put in the CPU's register even I declare it with register keyword. And the error I code in the first block of code was just because of the C compiler's ability to flag it as error. (C compiler sees it as syntax error)

So how do I know if it will be put in CPU's register? What is the purpose of the keyword register if it won't do what it is supposed to do?

2.)
I remember during a programming class, I was taught that X86 architecture has 8 registers. Since most CPU are using X86 architecture including intel P4, I wonder if P4 also only has 8 registers?

3.)
I have heard that VS.Net 03 has a way to optimize for the P4, so how do I do that?

Thanks.
GeneralRe: Questions on the keyword &quot;register&quot; in C &amp; C++ Pin
Ryan Binns7-Jul-04 16:31
Ryan Binns7-Jul-04 16:31 
GeneralRe: Questions on the keyword &quot;register&quot; in C &amp; C++ Pin
Paul Ranson8-Jul-04 0:00
Paul Ranson8-Jul-04 0:00 
GeneralRe: Questions on the keyword &quot;register&quot; in C &amp; C++ Pin
Link26008-Jul-04 13:39
Link26008-Jul-04 13:39 
GeneralRe: Questions on the keyword &quot;register&quot; in C &amp; C++ Pin
Paul Ranson9-Jul-04 0:47
Paul Ranson9-Jul-04 0:47 
GeneralC++ questions - memory allocation speed and using an instance of a class Pin
Indrawati7-Jul-04 14:04
Indrawati7-Jul-04 14:04 
GeneralRe: C++ questions - memory allocation speed and using an instance of a class Pin
palbano7-Jul-04 16:58
palbano7-Jul-04 16:58 
GeneralHelp managing test code Pin
Gavin Stark7-Jul-04 14:04
Gavin Stark7-Jul-04 14:04 
QuestionDont lose focus? Pin
Larsson7-Jul-04 13:16
Larsson7-Jul-04 13:16 
AnswerRe: Dont lose focus? Pin
Ken Mazaika7-Jul-04 13:34
Ken Mazaika7-Jul-04 13:34 
GeneralRe: Dont lose focus? Pin
Larsson7-Jul-04 13:37
Larsson7-Jul-04 13:37 
GeneralRe: Dont lose focus? Pin
Ken Mazaika7-Jul-04 13:42
Ken Mazaika7-Jul-04 13:42 
GeneralRe: Dont lose focus? Pin
Larsson7-Jul-04 13:44
Larsson7-Jul-04 13:44 
GeneralRe: Dont lose focus? Pin
Ken Mazaika7-Jul-04 13:51
Ken Mazaika7-Jul-04 13:51 
GeneralRe: Dont lose focus? Pin
Larsson7-Jul-04 13:54
Larsson7-Jul-04 13:54 
AnswerRe: Dont lose focus? Pin
ThatsAlok7-Jul-04 21:56
ThatsAlok7-Jul-04 21:56 
GeneralDialog Box Pin
Ken Mazaika7-Jul-04 13:06
Ken Mazaika7-Jul-04 13:06 
GeneralCommand line arguments.. Pin
Laing,James7-Jul-04 12:17
Laing,James7-Jul-04 12:17 

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.