Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Register

Reply
Thread Tools

Register

 
 
raghu
Guest
Posts: n/a
 
      11-16-2006
#include<stdio.h>
register int i=9;
int main(void)
{
register int i=8;
int *p;
p=&i;
printf("%d",*p);
return 0;
}

I compiled this code in Turbo C/C++.It gave two errors as: Register int
cant be used as global and pointer cant be applied to the register int.

When I compiled the same in Miracle C compiler it compiled succesfully
and gave output as 8.

I think Turbo C/C++ compiler is correct as I have read in books that
pointer cant be applied variables of register storage class.

Why this differentiation in compilers?

Dont they follow the same rules of C?

Please help.

Regards,
Raghu

 
Reply With Quote
 
 
 
 
jaysome
Guest
Posts: n/a
 
      11-16-2006
On 15 Nov 2006 23:22:25 -0800, "raghu" <(E-Mail Removed)> wrote:

>#include<stdio.h>
>register int i=9;
>int main(void)
>{
>register int i=8;
>int *p;
>p=&i;
>printf("%d",*p);
>return 0;
>}
>
>I compiled this code in Turbo C/C++.It gave two errors as: Register int
>cant be used as global and pointer cant be applied to the register int.
>
>When I compiled the same in Miracle C compiler it compiled succesfully
>and gave output as 8.
>
>I think Turbo C/C++ compiler is correct as I have read in books that
>pointer cant be applied variables of register storage class.
>
>Why this differentiation in compilers?
>
>Dont they follow the same rules of C?
>
>Please help.
>
>Regards,
>Raghu


This code should not compile. This line:

register int i=9;

uses an inappropriate storage class (register) for an object with
external linkage (or, for that matter, any object that is not an auto
declaration).

Even if you remove the above line, I don't think you can take the
address of a "register".

The "register" keyword should be considered obsolete and off-limits,
unless you really, really know what you're doing and have a really
good argument to justify its usage. A good rule of thumb is to never,
ever use it.

--
jay
 
Reply With Quote
 
 
 
 
Richard Heathfield
Guest
Posts: n/a
 
      11-16-2006
raghu said:

> #include<stdio.h>
> register int i=9;
> int main(void)
> {
> register int i=8;
> int *p;
> p=&i;
> printf("%d",*p);
> return 0;
> }
>
> I compiled this code in Turbo C/C++.It gave two errors as: Register int
> cant be used as global and pointer cant be applied to the register int.


That's correct.

> When I compiled the same in Miracle C compiler it compiled succesfully
> and gave output as 8.


If you invoke it in conforming mode, it *must* issue a diagnostic message
for the above code, but it is allowed to continue to translate the code and
even produce an executable program. (If you don't invoke it in conforming
mode, it isn't a C compiler as far as comp.lang.c is concerned.)

If you're not getting a diagnostic message from Miracle C for taking the
address of a register, you're not invoking it in conforming mode. (That
doesn't amount to a claim that Miracle C /has/ a conforming mode, on which
I have no opinion either way, since AFAIK I've never used it.)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: normal service will be restored as soon as possible. Please do not
adjust your email clients.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to register a custom class name in c#? jay ASP .Net 0 02-19-2004 07:06 AM
Register problem(long) Morfeusz VHDL 4 12-03-2003 09:35 AM
synthese: date and time automatically placed in a register?? Pierre-Louis VHDL 8 10-17-2003 05:56 PM
need the code for linearfeedback register yoga VHDL 1 10-11-2003 01:08 AM
(newbie) 2 read/write register Max VHDL 1 09-04-2003 12:44 PM



Advertisments