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

Runtime Structure

Hi EveryBody!
i need a information about creatting structure at runtime....
like example
.....
int main()
{
char *a,*b;
printf("Enter the structure");
scanf("%s",a);
printf ("Enter The Datatype");
scanf("%s",b);
create(a,b);
}
void create(char *F,Char *G);
{
struct F
{
G a;
}
}

i hope u will understand this program... this example ,but i need
inforamtion any possibleties to create struct and its field in runtime
, that user will define..
if posssible give me reply
Thanks
BY
CNS

Nov 15 '05 #1
3 5557
"chellappa" <N.*********@gmail.com> wrote in message
news:11*********************@g14g2000cwa.googlegro ups.com...
Hi EveryBody!
i need a information about creatting structure at runtime....
like example
....
int main()
{
char *a,*b;
printf("Enter the structure");
scanf("%s",a);
printf ("Enter The Datatype");
scanf("%s",b);
create(a,b);
}
void create(char *F,Char *G);
{
struct F
{
G a;
}
}

i hope u will understand this program... this example ,but i need
inforamtion any possibleties to create struct and its field in runtime
, that user will define..
if posssible give me reply


1. To create something in runtime you first need allocate memory to it
provided you know the size of that something.
2. It is impossible to define (note, not create) something in a C program
after it has been compiled. C programs are compiled, not interpreted. I they
had been interpreted, it would probably have been possible to define
something on the go. Hence, interpretation is to be done by you...
3. Think well whether this is indeed what you need in your program. Can't
you define all what need in the program and then create one of those known
things?
4. What you can do though is...
4a. generate C source code for another program in your original program,
compile and run it -- not sure it's suitable but it's possible
4b. in your program ask the user exactly what he needs inside the structure
(what types), calculate offsets and sizes of the members so that it would be
possible to allocate enough memory for the structure and fill in all its
members at proper addresses

HTH
Alex
P.S. Consider (3) or (4b)
Nov 15 '05 #2
chellappa said:
Hi EveryBody!
i need a information about creatting structure at runtime....
<snip>
i hope u will understand this program... this example ,but i need
inforamtion any possibleties to create struct and its field in runtime
, that user will define..
if posssible give me reply


This is much harder than you think. It is, however, possible, sort of, kind
of, in a way. (Are you there, Jamison Ch? Do you remember FFD?)

But you effectively end up (almost) writing your own database engine. I
doubt very much whether you really want to go to that much effort. We are
talking several weeks of development and testing here, and at the end you
probably won't get the syntax you wanted anyway. (What you will get is the
ability to store arbitrary data, the type or types of which is decided at
runtime.)

Think very carefully before embarking on such a course.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/2005
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Nov 15 '05 #3

chellappa wrote:
Hi EveryBody!
i need a information about creatting structure at runtime....
like example
....
int main()
{
char *a,*b;
printf("Enter the structure");
scanf("%s",a);
printf ("Enter The Datatype");
scanf("%s",b);
create(a,b);
}
void create(char *F,Char *G);
{
struct F
{
G a;
}
}

i hope u will understand this program... this example ,but i need
inforamtion any possibleties to create struct and its field in runtime
, that user will define..
if posssible give me reply
Thanks
BY
CNS


You can't define a C struct at runtime, at least not in the way you're
expecting.

You *can* use structs and unions to create dynamic records, but it's a
bit of work, and I can't toss off an example right now. If I get a
chance tonight I'll work on a simple example.

Nov 15 '05 #4

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

Similar topics

7
by: José Teixeira Junior | last post by:
I need add one new unknown control at runtime and the only one information that i have is one string with type of control. Example: c = "System.Windows.Forms.TextBox" How i can create one...
2
by: Dave | last post by:
Hello all, I am creating a linked list implementation which will be used in a number of contexts. As a result, I am defining its value node as type (void *). I hope to pass something in to its...
3
by: Jebrew | last post by:
Okay, so the deal is, I'm using the enum structure to populate some list, the problem is that I don't have the enums at compile time, they must be generated at runtime (i.e. read from some file or...
11
by: tony.fountaine | last post by:
I don't think this is possible but, if anyone has comments on a work around that would be great. Let me explain the reason I would like to do this. Suppose you are given a file that contains a...
9
by: Dieter | last post by:
Hi All, I am trying to dynamically implement (declare/define) a structure within a function. The reason being, is that this structure would contain a variable number of members of various...
5
by: Steve Bugden | last post by:
Hi, I would like to set the column widths in the ASP.NET GridView control at runtime I have tried the following: http://msdn2.microsoft.com/en-us/library/ms178296.aspx Which uses the...
4
by: Rob Dob | last post by:
Hi, I have a global structure that I declare within form1.cs, and I need to reference from within other forms, everything seems to work okay at runtime, Everything works okay however I get...
1
by: conckrish | last post by:
Hi all, Can anyone tell me how to find out the memory used by a DataTable at runtime? I am appending lot of data to datatable at runtime.I have to measure this memory comsumption...
17
by: blufox | last post by:
Hi All, Can i change the execution path of methods in my process at runtime? e.g a()->b()->c()->d()->e() Now, i want execution to be altered at runtime as -
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.