LinuxQuestions.org
Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-29-2006, 08:22 PM   #1
taras masnyj
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Rep: Reputation: 0
Smile grouping variable locations


Hi,

I'm new to this forum. I am porting an embedded app to a linux PC.

I need to make the locations of a set different types of variables
go into a small, well defined address range. These are global variables that can NOT be put into a structure without having
to change a lot of existing code.


Example:

int dummy1;
struct dummy2;
struct dummy3;
int dummy4;


By using debug printfs on my target machime (a linux pentium PC)
I see that the final addresses of the variables are scattered
over a wide range.

Are there any linker or other GCC methods of doing this?
Any suggestions will be appreciated.
 
Old 09-30-2006, 12:30 AM   #2
Dan04
Member
 
Registered: Jun 2006
Location: Texas
Distribution: Ubuntu
Posts: 207

Rep: Reputation: 37
Quote:
Originally Posted by taras masnyj
I need to make the locations of a set different types of variables
go into a small, well defined address range. These are global variables that can NOT be put into a structure without having to change a lot of existing code.
Yes they can!

Code:
struct {
   int var1;
   char *var2;
   double var3;
} globals;

#define var1 globals.var1
#define var2 globals.var2
#define var3 globals.var3
 
Old 10-02-2006, 09:11 PM   #3
taras masnyj
LQ Newbie
 
Registered: Sep 2006
Posts: 2

Original Poster
Rep: Reputation: 0
Thanks Dan,

Your reply is clever however I would still need to
recode other files where the global variables are
referenced. Using a simple form of your example:

struct {
int var1;
} globals;

#define var1 globals.var1

If var1 is originally declared as int var1 and
as extern int var1 in other files, redefining
var1 using the structure and the #define causes
compiler errors in the extern declarations in
the other files. I tried it.

I solved my problem the long way by doing separate address
range checks for each of the global variables.

Best Regards
tgm
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
setting a variable variable in a script... this works, but could it be more elegant? pwc101 Programming 3 08-18-2006 12:23 PM
Scripting: accessing a variable stored in a variable? tomolesonjr Linux - Newbie 5 05-05-2006 09:47 PM
Squid User Grouping dan0r Linux - Software 1 03-06-2006 12:14 PM
Gnome Grouping Windows maelstrom209 Linux - Software 1 12-25-2004 07:58 PM
bash - while + until loops grouping? trees Linux - General 2 02-19-2004 03:29 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:31 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration