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 3 5603
"chellappa" <N.*********@gm ail.com> wrote in message
news:11******** *************@g 14g2000cwa.goog legroups.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)
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)
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 textbox at runtime in my form1?
|
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 "constructor" so that I
will be able to manipulate my list without the need for constant
casting; some sort of runtime type-safety mechanism.
For example, I want a linked lists of ints. I want to be able to say:
|
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 what not). I need them to
be in the enum type of structure for a specific control that I've built (and
don't want to rebuild in some other manner). Is there a way to generate an
enum at runtime or am I stuck making a class that acts like the...
|
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 header defining
a structure for a set of data that is contained in the file. If you do
not know what the structure is before you read the header of the file
how would you work with this in code?
Any comments would be greatly appreciated.
|
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 possible types depending on what's
passed to it, and then be returned via pointer to the dynamically
allocated memory.
I'm sure that there are various ways to do this (ie: linked lists, void
types...,etc) but I can't seem to put my finger on it...
| |
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 following code on a button:
Protected Sub Button1_Click(ByVal sender As Object, _
|
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 the following warning when I compile:
Warning 2 Accessing a member on 'MYCMS.Form1.GLCurrentUserInfo' may cause a
runtime exception because it is a field of a marshal-by-reference class
C:\MYCMS\Form2.cs
|
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 programatically...
Plz help me...
Thanx in advance...
Jacob...
|
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 -
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |