473,322 Members | 1,781 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,322 software developers and data experts.

Register

#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

Nov 16 '06 #1
2 2085
On 15 Nov 2006 23:22:25 -0800, "raghu" <ra*********@gmail.comwrote:
>#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
Nov 16 '06 #2
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.
Nov 16 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: G Kannan | last post by:
Hey all! I have written a perl script to retrieve information from a HTML Form and insert the data into an Oracle database table. I am gettting the the following error message: "Use of...
12
by: Ioannis Vranos | last post by:
Just some thought on it, wanting to see any explanations. It was advised in this newsgroups that we should avoid the use of keyword register. However it is a language feature, and if it...
3
by: Alex | last post by:
I apoligise in advance if this is an os or platform based question, I don't know. I was wondering how register integers (and other types of register variables) are managed by c++. For example,...
14
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
9
by: Jackie | last post by:
Hi everyone, Does anyone know when "register" declarations should be used and when "register" must not be used? If possible please give examples for both cases. Thanks
29
by: orium69 | last post by:
hi everyone, i'm wondering if there is a way to have sure that a variable is allocated in the cache, after its declaration with "register"? Tks!
33
by: Snis Pilbor | last post by:
With the "as if" rule in play, doesn't that effectively render the "register" keyword completely useless? Example: I make a silly compiler which creates code that goes out of its way to take a...
5
by: prouleau001 | last post by:
Hi all! Since that the decorator syntax is upon us, I think it would be good if atexit.register() was returning the function passed as argument. This simple change to the library would solve a...
26
by: Vashna | last post by:
Hi Group, I have a doubt about register variables. I know that if we have a variable used very frequently in a function, then provided we never apply the & function to it, we can define it as...
21
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.