Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > Mac OS X Development Forums > Objective-C, Python, Ruby Development

Reply
 
LinkBack Thread Tools Display Modes
Old 09-09-2010, 04:35 AM   #1 (permalink)
Registered Member
 
Join Date: Sep 2010
Posts: 2
itralala is on a distinguished road
Default Variable (Variable name) ?

Hello,

I'm currently migrating my dev team from Windev Mobile language (a RAD tool for developping WM applications) to Objective-C / Cocoa.

One of the most powerfull feature of Windev Mobile is the dynamic variable name (it also exists in PHP / Java).

For exemple :

Code:
int var1 = 2;
int var2 = 17;
int i = 1;
NSLog(@"%d", var & i) ---> would display 2
int i = 2;
NSLog(@"%d", var & i) ---> would display 17
So, is this possible to use dynamic variable name syntax ?

Thank you,

Vincent
itralala is offline   Reply With Quote
Old 09-10-2010, 06:37 PM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 327
thomashw is on a distinguished road
Default

You can do it using macros and using the ## operator. This operator will join to tokens into a single token.

So if you had an integer named x20, you could do something like this at the top of your code:

Code:
#define printx(n)  printf (”%i\n”, x ## n)
To call it in your code you'd write this:

Code:
printx (20);
Which would result in this:

Code:
printf (”%i\n”, x20);
Hope that helps.
thomashw is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 478
15 members and 463 guests
7twenty7, AlanFloyd, AppsBlogger, David-T, iAppDeveloper, imac74, Jaxen66, lovoyl, Music Man, mutantskin, Sami Gh, SLIC, solardrift, unicornleo, usernametaken
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,683
Threads: 94,131
Posts: 402,932
Top Poster: BrianSlick (7,990)
Welcome to our newest member, unicornleo
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 10:11 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0