473,395 Members | 1,905 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,395 software developers and data experts.

naming variables by parameter

3
Hi all,
I'm starting in C and having problem with naming variables. I have this function:

void new (int a)
{
int new_"$a";
.
.
.
}

I'd like to replace "$a" with the content of variable a. It's possible to be done in C?

Thank you for any help.
Aug 18 '07 #1
6 1369
Banfa
9,065 Expert Mod 8TB
Hi all,
I'm starting in C and having problem with naming variables. I have this function:

void new (int a)
{
int new_"$a";
.
.
.
}

I'd like to replace "$a" with the content of variable a. It's possible to be done in C?

Thank you for any help.
No it's not possible and anyway it would be pointless. You have declared new_??? as a stack variable so it only exists for the lifetime of the function call.

Anyway neither C nore C++ support this sort of variable variables names (as would be available in some scripting languages (PHP springs to mind)).

I think you might do better if you describe what you are trying to achieve then may be we could suggest a way to do it.
Aug 18 '07 #2
weaknessforcats
9,208 Expert Mod 8TB
Since this is C and not C++, you couild check out the preprocessor token pasting operator ## and write a macro for this.

Just don't do this in C++ as there are alternate ways to do this.
Aug 18 '07 #3
flinks
3
No it's not possible and anyway it would be pointless. You have declared new_??? as a stack variable so it only exists for the lifetime of the function call.

Anyway neither C nore C++ support this sort of variable variables names (as would be available in some scripting languages (PHP springs to mind)).

I think you might do better if you describe what you are trying to achieve then may be we could suggest a way to do it.
Thank you for reply.
I thought in this because I write in bash, and it's is possible there.
my problem is the follow:

My program will receive a list of n number, depending on some tests it must be added to an existent linked list or then the program must create a new one to add then. I can do it of any way, but there is some considerations:
I don't know how many numbers will enter;
I don't know how many lists will be needed;
I must use linked lists in the solution;

I'll be very grateful if someone help me or indicate some material to I study.
Aug 18 '07 #4
Banfa
9,065 Expert Mod 8TB
OK so you need a variable number of lists containing a variable number of numbers.

It isn't nice which I would use a 2 layer linked list.

That is I would have a linked list of structures that contained the criteria and the head pointer to the sublists of numbers.

Of course if you where using C++ then I would suggest using the STL map and list classes.

Do you know how to construct a basic linked list?
Aug 18 '07 #5
Banfa
9,065 Expert Mod 8TB
Since this is C and not C++, you couild check out the preprocessor token pasting operator ## and write a macro for this.
Not at runtime, the preprocessor runs as part of the compiler.
Aug 18 '07 #6
flinks
3
OK so you need a variable number of lists containing a variable number of numbers.

It isn't nice which I would use a 2 layer linked list.

That is I would have a linked list of structures that contained the criteria and the head pointer to the sublists of numbers.

Of course if you where using C++ then I would suggest using the STL map and list classes.

Do you know how to construct a basic linked list?
I'm starting in linked lists today, but already can do the basic operations. I'll try to do the "nested" linked list, it seems possible. Thank you for the help.
Aug 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Mark Broadbent | last post by:
stupid question time again to most of you experts but this is something that continually bothers me. I am trying to get into the habit of naming variables and controls in an assembly as per...
3
by: Gustaf Liljegren | last post by:
Here's a small "problem" I often run into. The argument names in the constructor are usually the same as the those I want to store away as class variables. This example shows the problem and how I...
5
by: Allan Ebdrup | last post by:
Does anyone have some good pointers to good naming conventions preferrably by MS. Another developer and I had a discussion on the naming of a public property that contains a collection of...
3
by: John Salerno | last post by:
Does Microsoft have any naming guidelines for variables? I've been reading their guidelines for just about every other type (methods, parameters, properties, etc.) but nothing about variables. Are...
48
by: Robert Jacobson | last post by:
Hello all, If I have a class called "Foo," is there a preferred naming convention for iterating through each Foo instance in a collection of Foos? I've seen several different variations, even...
0
by: Carl Colijn | last post by:
Hi all, Disclaimer: before I might trigger your "let's start a holy war!" button, I'd like to say I'm not intended to; I just post this message to get some input and not to promote "Yet Another...
3
by: Phillip Conrad | last post by:
Here is a little problem I've run into, and none of the naming conventions have helped... Ever since I switched from C to C# and FxCop, I've going crazy trying to fix some style issues. I have 3...
114
by: Jonathan Wood | last post by:
I was just wondering what naming convention most of you use for class variables. Underscore, "m_" prefix, camel case, capitalized, etc? Has one style emerged as the most popular? Thanks for...
8
by: mrashidsaleem | last post by:
Can anyone guide me what is wrong with the naming conventions suggested below? I know that this is not recommended by many (including Microsoft) but I need to know what exactly is the rationale...
17
by: Miguel Guedes | last post by:
Hello, Does anyone have a link to the C++ Standard Library naming conventions that they could share? I have found a few links to pages on C++ naming conventions but am unsure as to what standard...
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: 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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.