Solved

pls help - declaring a register variable

Posted on 2011-02-21
5
227 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
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 33

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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

Have you thought about creating an iPhone application (app), but didn't even know where to get started? Here's how: ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ ~ Important pre-programming comments: I’ve never tri…
Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
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 and use switch statements in the C programming language.

839 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