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

The C have eval function?

Many Language have eval function.The C have eval function?
How to execute c code in c ?
Can i execute c code from a variable(like perl's code ref)?
Or i must do this job by using yacc & lex ?
All of the non-interpreted languages have no eval function?


May 22 '07 #1
8 13234
sonet wrote:
Many Language have eval function.The C have eval function?
No.
How to execute c code in c ?
Compile it and run the result.
Can i execute c code from a variable(like perl's code ref)?
No.
Or i must do this job by using yacc & lex ?
?
All of the non-interpreted languages have no eval function?
Probably

--
Ian Collins.
May 22 '07 #2
sonet said:
Many Language have eval function.The C have eval function?
Not unless you write one.
How to execute c code in c ?
Write a C interpreter in C, or use an existing one.
Can i execute c code from a variable(like perl's code ref)?
C has no syntax for this. Nor does a typical implementation provide this
functionality as an extension.
Or i must do this job by using yacc & lex ?
You /could/ do it that way, yes.
All of the non-interpreted languages have no eval function?
C doesn't mandate either compilation or interpretation - only
translation - but yes, it is generally regarded as a "compiled
language" - i.e. a language for which typical implementations are
compilers rather than interpreters (although C interpreters do exist).
And yes, compilers do tend to throw away the symbol table once they're
done with it, making eval an impractical, and perhaps impossible, task.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
May 22 '07 #3
sonet wrote:

(fx:foreshadowing "important question")
Many Language have eval function.The C have eval function?
Standard C has no built-in `eval` function.
How to execute c code in c ?
You'd have to do it in a non-portable way, such as using `system`
to run the C compiler, generate a loadable library, and then
system magic to load and execute that library. (fx:mumble)
POSIX, comp.unix.programmer.
Can i execute c code from a variable(like perl's code ref)?
No.
Or i must do this job by using yacc & lex ?
That would mean writing a C compiler. That's a lot of hard
work. Don't go there. (Someone else might have gone there,
or somewhere like it.)
All of the non-interpreted languages have no eval function?
There are compiled languages with an eval function; Common Lisp and
Poplog's Pop11, to name two.

(Depending on exactly what you mean by `compiled`. The Pop11 compiler
compiles on-the-fly to native code. So does at least one Common
Lisp.)

Important Question: /why do you want to know/? Is it mere curiosity,
or do you have an actual problem you want to solve? In that case,
telling us about that problem might get you a more useful answer.

--
"Go not to the Elves for counsel, for they will answer both no and yes."/tLotR/

Hewlett-Packard Limited registered no:
registered office: Cain Road, Bracknell, Berks RG12 1HN 690597 England

May 22 '07 #4
Sorry my english is very poor!

In perl we can do this.

$a=1;
$coderef=qq{
\$b=\$a?1:0;
};
eval $coderef;
# The result is 1
print $b;
================================================== ===================
The tcsh(c shell) is like the eval function. We can write a piece of code ,
and execute the
code.
The eval is very useful. I can prepare any code outside the program. If the
program is a filter
process. It can add any filter case to the program. And the filter case have
logic not only
normal data.
"sonet" <so*******@msa.hinet.net¼¶¼g©ó¶l¥ó·s»D:f2********* *@netnews.hinet.net...
Many Language have eval function.The C have eval function?
How to execute c code in c ?
Can i execute c code from a variable(like perl's code ref)?
Or i must do this job by using yacc & lex ?
All of the non-interpreted languages have no eval function?

May 22 '07 #5
On May 22, 12:51 pm, "sonet" <sonet....@msa.hinet.netwrote:
Many Language have eval function.The C have eval function?
How to execute c code in c ?
Can i execute c code from a variable(like perl's code ref)?
Or i must do this job by using yacc & lex ?
All of the non-interpreted languages have no eval function?
There is no equivalent of eval in C. That is because in C the code has
t be known at compile time to be ... well ... compiled. In python/perl/
javascript, you have the code evaluated at runtime.

May 22 '07 #6
sonet wrote, On 22/05/07 11:56:
Sorry my english is very poor!
<snip>

Please do not top post, even when replying to yourself. Your reply
belongs under or interspersed with the message you are replying to. See
all the posts replying to you for examples.

Everyone understood what you meant when you referred to an eval
function, what did you not understand about the responses?
--
Flash Gordon
May 22 '07 #7
On May 22, 11:02 am, Richard Heathfield <r...@see.sig.invalidwrote:
sonet said:
Many Language have eval function.The C have eval function?

Not unless you write one.
How to execute c code in c ?

Write a C interpreter in C, or use an existing one.
Can i execute c code from a variable(like perl's code ref)?

C has no syntax for this. Nor does a typical implementation provide this
functionality as an extension.
Probably in most implementations you can execute such code by cleverly
using the variable to overflow a buffer, possibly passing to inline
assembler to mess around with stack pointers or whatever... but any
such solution seems doomed to be non-portable and require assumptions
beyond those that can be justified from the C standard.
Or i must do this job by using yacc & lex ?

You /could/ do it that way, yes.
All of the non-interpreted languages have no eval function?

C doesn't mandate either compilation or interpretation - only
translation - but yes, it is generally regarded as a "compiled
language" - i.e. a language for which typical implementations are
compilers rather than interpreters (although C interpreters do exist).
And yes, compilers do tend to throw away the symbol table once they're
done with it, making eval an impractical, and perhaps impossible, task.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999http://www.cpax.org.uk
email: rjh at the above domain, - www.

May 22 '07 #8
Fr************@googlemail.com writes:
On May 22, 11:02 am, Richard Heathfield <r...@see.sig.invalidwrote:
>sonet said:
[...]
Can i execute c code from a variable(like perl's code ref)?

C has no syntax for this. Nor does a typical implementation provide this
functionality as an extension.

Probably in most implementations you can execute such code by cleverly
using the variable to overflow a buffer, possibly passing to inline
assembler to mess around with stack pointers or whatever... but any
such solution seems doomed to be non-portable and require assumptions
beyond those that can be justified from the C standard.
A more plausible way to do that might be to build a buffer containing
the executable code, then somehow construct a function pointer from
the buffer's address. But that's still horribly non-portable.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
"We must do something. This is something. Therefore, we must do this."
-- Antony Jay and Jonathan Lynn, "Yes Minister"
May 22 '07 #9

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

Similar topics

4
by: Jean-Sébastien Bolduc | last post by:
Hello, I would like to associate a local namespace with a lambda function. To be more specific, here is exactly what I would want: def foo(): a = 1 f = lambda x : a*x return f
9
by: HikksNotAtHome | last post by:
This is a very simplified example of an Intranet application. But, is there an easier (or more efficient) way of getting the decimal equivalent of a fraction? The actual function gets the select...
12
by: knocte | last post by:
Hello. I have always thought that the eval() function was very flexible and useful. If I use it, I can define functions at runtime!! However, I have found a case where eval() does not work...
18
by: Joe Fallon | last post by:
I have some complex logic which is fairly simply to build up into a string. I needed a way to Eval this string and return a Boolean result. This code works fine to achieve that goal. My...
3
by: Pauljh | last post by:
Hi All, I'm running some javascript over a server side generated web page and have multiple generated empty select statements, that I want to populate when the page is loaded. As HTML doesn't do...
7
by: Darko | last post by:
Hello, I have this particular problem with eval() when using Microsoft Internet Explorer, when trying to define an event handler. This is the code: function BigObject() { this.items = new...
6
by: vasudevram | last post by:
Hi group, Question: Do eval() and exec not accept a function definition? (like 'def foo: pass) ? I wrote a function to generate other functions using something like eval("def foo: ....") but...
2
by: Florian Loitsch | last post by:
hi, What should be the output of the following code-snippet? === var x = "global"; function f() { var x = 0; eval("function x() { return false; }"); delete x; alert(x); }
6
by: RandomElle | last post by:
Hi there I'm hoping someone can help me out with the use of the Eval function. I am using Access2003 under WinXP Pro. I can successfully use the Eval function and get it to call any function with...
10
by: Gordon | last post by:
I have a script that creates new objects based on the value of a form field. Basically, the code looks like this. eval ('new ' + objType.value + '(val1, val2, val3'); objType is a select with...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
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
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...

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.