1. RE: How can I pass an atom to a C function as C float or double

>From: Al Getz <Xaxo at aol.com>
>Subject: RE: How can I pass an atom to a C function as C float or double
>
>
>euman at bellsouth.net wrote:
> >
> >
> > On 12 Sep 2003 at 23:27, myotis at xnet.ro wrote:
> >
> > > Please tell me how can I pass an atom as a C float to a C
> > > function from a dll. The same question is for a C double ...
> > >
> > > Example of the C function in DLL :
> > >
> > > float MyFunction( float parameter1, double parameter2 );
> > >
> > > I have tried all the posible combinations ( C_FLOAT in define the C
> > > function, atom_to_float32 when I pass the arguments ... nothing work )
> > >
> > > Please write to me a little piece of euphoria code that call this
> > > function in Euphoria. Also tell me the calling convention you are 
>write
> > > for ...
> > > I can change this in my DLL as I want.
> > >
> > > Also, please tell me if the version of euphoria you are
> > > writeing for the example, matter for some reason.
> > >
> > > Thank you !
> >
> > Can you try this:
> >
> > integer junk
> > junk = allocate(5)
> > poke(junk, atom_to_float32(x))
> > poke4(junk+1, atom_to_float64(y))
> >

What is this??
Firstly, junk is a memory address, so it should be an atom.
Secondly, atom_to_float32() returns 4 bytes, not 1, so the subsequent poke 
will overwrite it.
Thirdly, atom_to_float64() returns 8 bytes, times 4, making 32, which 
wouldn't fit in the allocated 5.
Fourthly, you don't even need pointers.

> > then pass your params the pointer to "junk"
> >
> > f = Myfunction(peek(junk),peek4(junk+1))
> >
> >
>Hello there,
>
>Good idea Wayne, i was thinking he wanted to pass by value,
>but did you mean to say:
>     f = Myfunction(junk,junk+1)
>or just
>     f = Myfunction(junk)
>instead?
>
>Take care for now,
>Al

Uh, for pass by value, what are you using pointers for? Simply define the 
function with C_FLOAT or C_DOUBLE and use the atom as the parameter.

--for: float MyFunction( float parameter1, double parameter2 );

constant
xMyFunction = define_c_func(dll, "MyFunction", {C_FLOAT, C_DOUBLE}, C_FLOAT)

global function MyFunction(atom param1, atom param2)
    return c_func(xMyFunction, {param1, param2})
end function

new topic     » topic index » view message » categorize

2. RE: How can I pass an atom to a C function as C float or double

<?xml  version="1.0" ?><html>
<head>
<title></title>
</head>
<body>
<div align="left"><font face="Arial"><span style="font-size:10pt">On 12 Sep 2003
at 22:31, Elliott Sales de Andrade wrote:</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; On 12 Sep 2003 at 23:27, myotis at xnet.ro
wrote:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; Please tell me how can I pass an atom
as a C float to a C</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; function from a dll. The same question
is for a C double ...</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; Example of the C function in DLL
:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; float MyFunction( float parameter1,
double parameter2 );</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; I have tried all the posible
combinations ( C_FLOAT in define the C</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; function, atom_to_float32 when I pass
the arguments ... nothing work )</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; Please write to me a little piece of
euphoria code that call this</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; function in Euphoria. Also tell me the
calling convention you are </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt;write</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; for ...</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; I can change this in my DLL as I
want.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; Also, please tell me if the version of
euphoria you are</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; writeing for the example, matter for
some reason.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; &gt; Thank you !</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; Can you try this:</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; integer junk</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; junk = allocate(5)</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; poke(junk,
atom_to_float32(x))</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt; poke4(junk+1,
atom_to_float64(y))</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; &gt; &gt;</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; What is this??</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; Firstly, junk is a memory address, so it should be an
atom.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; Secondly, atom_to_float32() returns 4 bytes, not 1,
so the subsequent poke </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; will overwrite it.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; Thirdly, atom_to_float64() returns 8 bytes, times 4,
making 32, which </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; wouldn't fit in the allocated 5.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; Fourthly, you don't even need
pointers.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&gt; </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">hmmm maybe I read this wrong....</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">atom_to_float64() returns a sequence of 8 bytes - a C
double. </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Use poke(material, atom_to_float64(1.0)) to store the 8
bytes </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">in memory. </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">poke4 will actually store 4*8 = 32 bytes - wrong.
</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">If you decide to use atom_to_float32() to store C
*floats*, </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">you can also use poke() to store the 4
bytes.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt"> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Regards, </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Rob Craig </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Rapid Deployment Software </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">http://www.RapidEuphoria.com </span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Sure, so this would mean that I had not allocated enough
space</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&quot;by 4 bytes&quot;. Elliot I want to thank
you.</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Here is a quote of her problem</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&lt;QUOTE&gt;</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">My problem is how to give to the function in DLL a corect
float value.</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">If I define the function as you say and I call the
function</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">atom x</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">atom y</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">x = 0.45</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">y = 0.4534 </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt"> </span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Myfunction(x, y)</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt"> then the function in dll seems to receive anything else
but not</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">0.45 value or 0.4534 ... ( even as a floting number ...
)</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">If I call</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Myfunction(atom_to_float32(x), atom_toFloat64(y))
Euphoria</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">say that I can not pass a sequence to a C function
...</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Diana.</span></font></div>
<div align="left"><br/>
</div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">&lt;/QUOTE&gt;</span></font></div>
<div align="left"><br/></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">So I thought
immedialty she needed to have pointers setup in ram</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">to pass to her .DLL</span></font></div>
<div align="left"><br/></div>
<div align="left"><font face="Arial"><span style="font-size:10pt">Have a good
day all,</span></font></div>
<div align="left"><font face="Arial" color="#7f0000"><span
style="font-size:10pt">Euman</span></font></div>
<div align="left"><br/>
</div>
<div align="left"></div>

new topic     » goto parent     » topic index » view message » categorize

3. RE: How can I pass an atom to a C function as C float or double

On 13 Sep 2003 at 10:12, euman at bellsouth.net wrote:

What the???

> 
> 
> <?xml  version="1.0" ?><html>
> <head>
> <title></title>

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu