Assign a name to a pointer variable from another variable

N

Nmishra

Hi,
I have a problem in assigning a name to a pointer dynamically from
another pointer.

e.g. if I have

char* name = "myPtr";

and I want to have a int pointer having the name as myPtr taking the
name from the variable name,

int *(*name) = int[10]...
this line of code gives me an error of type mismatch. I am using gcc
as my compiler.

and if i write as

int *name = int[10] it takes name as the variable identifier rather
than myPtr as the identifier.


Any help is appreciated.

Regards,
NMishra
 
M

Malcolm

Nmishra said:
I have a problem in assigning a name to a pointer dynamically from
another pointer.

e.g. if I have

char* name = "myPtr";

and I want to have a int pointer having the name as myPtr taking the
name from the variable name,

int *(*name) = int[10]...
this line of code gives me an error of type mismatch. I am using gcc
as my compiler.

and if i write as

int *name = int[10] it takes name as the variable identifier rather
than myPtr as the identifier.
C variable names exist only at compile time

void foo(void)
{
int alpha = 1;
int beta = 2;
char *vname = "alpha";
int *ptr;

/* totally illegal and impossible to work around */
ptr = & thing_named_by_vname;
}

It is not possible to mix symbol names with runtime char arrays.
 
N

Nmishra

Hi,
thanks for the reply. I tried a lot and i could also make that out
that its logically impossible to do that.

thanks.


Malcolm said:
Nmishra said:
I have a problem in assigning a name to a pointer dynamically from
another pointer.

e.g. if I have

char* name = "myPtr";

and I want to have a int pointer having the name as myPtr taking the
name from the variable name,

int *(*name) = int[10]...
this line of code gives me an error of type mismatch. I am using gcc
as my compiler.

and if i write as

int *name = int[10] it takes name as the variable identifier rather
than myPtr as the identifier.
C variable names exist only at compile time

void foo(void)
{
int alpha = 1;
int beta = 2;
char *vname = "alpha";
int *ptr;

/* totally illegal and impossible to work around */
ptr = & thing_named_by_vname;
}

It is not possible to mix symbol names with runtime char arrays.
 
D

Default User

Nmishra said:
Hi,
I have a problem in assigning a name to a pointer dynamically from
another pointer.


This is not something you can do, as Malcolm pointed out. So, why don't
you tell us what problem you are trying to solve, rather than your
broken solution to the problem. We can likely help.





Brian Rodenborn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,565
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top