?
Solved

Reference to vars into structs at runtime

Posted on 1998-11-20
9
Medium Priority
?
203 Views
Last Modified: 2010-04-15
Hi guys!, well i'm implementing pseudo-SQL support in our corporate software, and there is no repository of structs definitions, and what I need is to inject SQL commands and transate them into internal messages, but the problem is

  how do I resolve the ofset of a var into a struct by name?

[...]

I mean something like this
   SELECT Name, Addr, Tel
   FROM Clients
   WHERE Flg=0x006A AND ZIP=Zip.Get("2345")

the objects (Clients, ....) are hardware written into the proccess who parses the command, but I don't know how to resolve the names of the Clients struct into ofset struct, and of course, the type and the size.

I'm using gcc 2.7.2 on Linux, maybe there is some defined macros to resolve this, or will have to program a repository of objects and a composition of fields (with name, size, ofset,...).

Thank you!
0
Comment
Question by:trickle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 10

Expert Comment

by:rbr
ID: 1254508
Do you the compontents of the structure or to you nothing about it. If you know nothink about the structure it will be impossible since at runtime all references to the components are resolved be pointer with no information about the name, the size and the type. Otherwise you should be able to to a parse of the structure at the compile-time to generate some Macros which will help you to access the structure. Pls give me more information, so I will be able to help you.
      
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1254509
Store a _duplicate_ table of the names and scan this, for the reason rbr says

typedef struct {
 char szName[128] ;
} SADDRESS ;

Then in _duplicate_ information table store
SADDRESS is the name of a struct called SADDRESS thru the "SQL" interface

szName is at offset 0 in SADDRESS, and called "Name" in the "SQL" interface and is a null terminated string.
0
 

Author Comment

by:trickle
ID: 1254510
Ok!, but what I don't want is to write an array with all the vars and its ofsets, name and somewhat the type.

I know the macro Ofsetof(TYPE, MEMBER) can resolv at compile time the vars in the struct, but is a little tedious.
I just want to know if exists a way o dinamically reference a var by name, I mean just like gdb with the symbols inside (compiled with debug info).

Thank U!


0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 8

Expert Comment

by:Answers2000
ID: 1254511
There may be a compiler specific way, but there is no standard C way...the C standard does not specify anything about how/if symbol tables should be stored.

If there is a compiler specific way it is specific to the debug info generated by your compiler.

As you're using GNU you can download the compiler/debugger source, and figure out how it stores the symbol table.  Sadly this is probably more work (and a lot more fragile) than doing it the "hard" way
0
 
LVL 11

Expert Comment

by:alexo
ID: 1254512
#define offsetof(structure, member) (size_t)&(((structure*)0)->member)
0
 
LVL 8

Expert Comment

by:Answers2000
ID: 1254513
Alexo - That's compile time

I understand correctly, the Questioer wants - runtime resolution of names....which ain't really C/C++'s bag...

0
 
LVL 3

Expert Comment

by:elfie
ID: 1254514
FYI, i don't know about linux, but if it was HPUX you could try shl_findsym. (man shl_load)

maybe in linux there is some kind of equivalent call
0
 
LVL 4

Expert Comment

by:jos010697
ID: 1254515
Yep, check out you man pages for dlopen(), dlsym() and dlclose(). It still doesn't
buy you much though, because structure members don't have any linkage at all.

kind regards,

Jos aka jos@and.nl
0
 
LVL 1

Accepted Solution

by:
semuel earned 400 total points
ID: 1254516
Hello There.

the answer is simple: you cann't. you cann't even count on that one struct will be build the same as his "brother".

anyway, databases are very diffecult thing to do.

if you want to be able to make "structs" at runtime, you'll have to do this through your oun data structure, like a linked list were every item had two strings: one for his name, and one for his value. it's, of course, a very simple and not efficient data structure, but it's an example.

anyway, it won't be an easy work.

Semuel Fomberg.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Preface I don't like visual development tools that are supposed to write a program for me. Even if it is Xcode and I can use Interface Builder. Yes, it is a perfect tool and has helped me a lot, mainly, in the beginning, when my programs were small…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use for-loops in the C programming language.
Suggested Courses
Course of the Month14 days, 18 hours left to enroll

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question