?
Solved

pls help - declaring a register variable

Posted on 2011-02-21
5
Medium Priority
?
246 Views
Last Modified: 2012-06-27
hi,
i am trying to declare a register variable

register int a = (int *)malloc(z*sizeof(int));

the error that i get is register name not specified for a ..


0
Comment
Question by:zizi21
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 9

Expert Comment

by:AriMc
ID: 34947360
Please provide the complete error message. Also it would be helpful to know why you want a pointer to be a register variable.

0
 
LVL 9

Expert Comment

by:rawinnlnx9
ID: 34947719
void function (void)
{
register int a;
for (a = 0; a < 10;a++)
 {
   printf ("%d", a); \\ Prints numbers 0 to 9

 }
}
0
 
LVL 11

Expert Comment

by:Deepu Abraham
ID: 34948450

if you are type casting to int* then you need to write like this:

register int* a = (int*)malloc(z*sizeof(int));

else

register int  a = malloc(z*sizeof(int));

Hope these link will clear your doubts:
http://geeksforgeeks.org/?p=4346
0
 
LVL 11

Accepted Solution

by:
Deepu Abraham earned 1600 total points
ID: 34948451
correction


register int* a = (int*)malloc(z*sizeof(int));

else

register int a = (int)malloc(sizeof(int));
0
 
LVL 35

Assisted Solution

by:sarabande
sarabande earned 400 total points
ID: 34950826
malloc returns a pointer and it makes not much sense to store that pointer into an integer. for many compilers pointers are 64 bit and int is 32 bit. there are also many compilers which would ignore the register keyword for example if the sizes doesn't match.

Sara
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand recursion in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question