473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Assign a name to a pointer variable from another variable

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
Nov 14 '05 #1
3 2717

"Nmishra" <nm*****@askcts.com> wrote in message
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.
Nov 14 '05 #2
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" <ma*****@55bank.freeserve.co.uk> wrote in message news:<c8**********@news8.svr.pol.co.uk>...
"Nmishra" <nm*****@askcts.com> wrote in message
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.

Nov 14 '05 #3
Nmishra wrote:

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
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

25
by: Rim | last post by:
Hi, I have been thinking about how to overload the assign operation '='. In many cases, I wanted to provide users of my packages a natural interface to the extended built-in types I created for...
4
by: steflhermitte | last post by:
Dear cpp-ians, I am working with a structure struct segment { .... vector <meta_segment>::iterator it_Z; .... };
18
by: ineedyourluvin1 | last post by:
Hi, I would appreciate if someone could tell me what I'm doing wrong ? #include<iostream> using namepace std ; struct person{ char *firstname ; int age ;
204
by: Alexei A. Frounze | last post by:
Hi all, I have a question regarding the gcc behavior (gcc version 3.3.4). On the following test program it emits a warning: #include <stdio.h> int aInt2 = {0,1,2,4,9,16}; int aInt3 =...
5
by: Orange | last post by:
hi, How to initialize the data variable. typedef struct { long len; BYTE data; }tag;
2
by: Mirovk | last post by:
Hi, I have a session variable wich value arrives from a previous .asp but in my actual page I need to modify it based upon a selected value from a radio button. I will try to figure out for...
2
by: mivey4 | last post by:
Hi. I am having a problem trying to find the proper way to assign a system object (or rather in this case a system object name) to a variable to use in my T-SQL code. I have to run a report...
2
by: mguy27 | last post by:
I am working with VBA in ExcelUltimately I am trying to take a huge amount of data (9500-10000 rows) and do a search for text including the words "Violated Door". I then want to take the rows (which...
9
by: raylopez99 | last post by:
Just an observation: pens for drawing lines in Win Forms are tricky when assignment is inside the paint handler. inside of the Paint handler, but not inside a "using" brace (that is, outside of...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.