• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

pls help - declaring a register variable

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
zizi21
Asked:
zizi21
2 Solutions
 
AriMcCommented:
Please provide the complete error message. Also it would be helpful to know why you want a pointer to be a register variable.

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

 }
}
0
 
Deepu AbrahamR & D Engineering ManagerCommented:

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
 
Deepu AbrahamR & D Engineering ManagerCommented:
correction


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

else

register int a = (int)malloc(sizeof(int));
0
 
sarabandeCommented:
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

Technology Partners: 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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now