Solved

pls help - declaring a register variable

Posted on 2011-02-21
5
218 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 32

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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

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…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures 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.

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now