473,586 Members | 2,620 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2100
On 15 Nov 2006 23:22:25 -0800, "raghu" <ra*********@gm ail.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
14135
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 uninitialized value in concatenation (.) at register.pl line 38, <STDIN> line 10." The PERL code is as follows:
12
2227
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 offers no help to an implementation, it is free to ignore it. And this happens widely, all my C++ compilers in my platform ignore this keyword.
3
2248
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, on a pentium 4, there are 8 register integers in the cpu. If you define more than 8, or if there are other programs using this space, how are the...
14
7901
by: aruna | last post by:
What is the disadvantage of using register storage class specifier?
9
8595
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
2456
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
3253
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 full 10 minutes every time a "register" declared variable is read from or written to. Besides this lag, everything else runs as expected. Then my...
5
1886
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 problem with the use of atexit.register as a decorator (and I can't think of any use case where this change would break any code). I describe the...
26
2204
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 a register variable and this will make it much faster to access. Now the question is: obviously there are only a fixed number of registers in our...
21
6321
by: JOYCE | last post by:
Look the subject,that's my problem! I hope someone can help me, thanks
0
7912
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
8202
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8338
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7959
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5710
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5390
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3865
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2345
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.