Solved

pls help - declaring a register variable

Posted on 2011-02-21
5
231 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:DeepuAbrahamK
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:
DeepuAbrahamK earned 400 total points
ID: 34948451
correction


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

else

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

Assisted Solution

by:sarabande
sarabande earned 100 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

Independent Software Vendors: 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

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…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use conditional statements in the C programming language.
The goal of this video is to provide viewers with basic examples to understand and use switch statements in the C programming language.

738 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