<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[variadische funktion]]></title><description><![CDATA[<p>ich arbeite aktuell bei einer kleinen funktionensammlung zum thema interpolationen (jaja rad neu erfinden und so...).</p>
<p>ich arbeite mit einem klassentemplate node, bei welchem man den datentyp, die dimensionen, die position und die auflösung einstellen kann.</p>
<p>für eine angenehmere bedienung habe ich eine funktion makenode gemacht, die eine variadische templatefunktion ist.</p>
<p>mein kleinstes kompilierbares beispiel:</p>
<pre><code>#include &lt;vector&gt;
#include &lt;cstdlib&gt;
#include &lt;cstdarg&gt;
#include &lt;iterator&gt;
#include &lt;iostream&gt;
namespace Interpolation
{
    unsigned long DefaultRes = 1;
    template&lt;class T, unsigned D&gt;
    struct Node
    {
        Node(T const *Data, unsigned long Resolution = DefaultRes);
        T Data[D];
        unsigned long Resolution;
    };
    template&lt;class T, unsigned D&gt;
    Node&lt;T, D&gt; MakeNode(T First, ...);
}
template&lt;class T, unsigned D&gt;
Interpolation::Node&lt;T, D&gt;::Node(T const *Data, unsigned long Resolution)
: Resolution(Resolution)
{
    for(unsigned i = 0; i &lt; D; i++)
        this-&gt;Data[i] = Data[i];
}
template&lt;class T, unsigned D&gt;
Interpolation::Node&lt;T, D&gt;
Interpolation::MakeNode(T First, ...)
{
    T Data[D] = {First};
    va_list Args;
    va_start(Args, First);
    for(unsigned i = 1; i &lt; D; i++)
        Data[i] = va_arg(Args, T);
    va_end(Args);
    return Interpolation::Node&lt;T, D&gt;(Data);
}
int main()
{
    using Interpolation::MakeNode;
    std::vector&lt; ::Interpolation::Node&lt;float, 2&gt; &gt; Data;
    Data.push_back(MakeNode&lt;float, 2&gt;(5, 5));
    std::cout &lt;&lt; Data.front().Data[0] &lt;&lt; ' ' &lt;&lt; Data.front().Data[1];
}
</code></pre>
<p>dieser code kompiliert, jedoch bekomme ich einen runtime error:<br />
<a href="http://ideone.com/TPaMLe" rel="nofollow">http://ideone.com/TPaMLe</a></p>
<blockquote>
<p><code>result: runtime error	 time: 0s memory: 2892 kB signal: 4 (SIGILL)</code></p>
</blockquote>
<p>ich kann mir diesen runtime error nicht erklären, ich hab den teil mit der variadik neu geschrieben um allenfällige tippfehler die mir nicht aufgefallen sind auszuschliessen, mit dem selben ergebnis.</p>
]]></description><link>https://www.c-plusplus.net/forum/topic/318779/variadische-funktion</link><generator>RSS for Node</generator><lastBuildDate>Sun, 26 Jul 2026 22:02:10 GMT</lastBuildDate><atom:link href="https://www.c-plusplus.net/forum/topic/318779.rss" rel="self" type="application/rss+xml"/><pubDate>Fri, 26 Jul 2013 08:08:40 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to variadische funktion on Fri, 26 Jul 2013 08:08:40 GMT]]></title><description><![CDATA[<p>ich arbeite aktuell bei einer kleinen funktionensammlung zum thema interpolationen (jaja rad neu erfinden und so...).</p>
<p>ich arbeite mit einem klassentemplate node, bei welchem man den datentyp, die dimensionen, die position und die auflösung einstellen kann.</p>
<p>für eine angenehmere bedienung habe ich eine funktion makenode gemacht, die eine variadische templatefunktion ist.</p>
<p>mein kleinstes kompilierbares beispiel:</p>
<pre><code>#include &lt;vector&gt;
#include &lt;cstdlib&gt;
#include &lt;cstdarg&gt;
#include &lt;iterator&gt;
#include &lt;iostream&gt;
namespace Interpolation
{
    unsigned long DefaultRes = 1;
    template&lt;class T, unsigned D&gt;
    struct Node
    {
        Node(T const *Data, unsigned long Resolution = DefaultRes);
        T Data[D];
        unsigned long Resolution;
    };
    template&lt;class T, unsigned D&gt;
    Node&lt;T, D&gt; MakeNode(T First, ...);
}
template&lt;class T, unsigned D&gt;
Interpolation::Node&lt;T, D&gt;::Node(T const *Data, unsigned long Resolution)
: Resolution(Resolution)
{
    for(unsigned i = 0; i &lt; D; i++)
        this-&gt;Data[i] = Data[i];
}
template&lt;class T, unsigned D&gt;
Interpolation::Node&lt;T, D&gt;
Interpolation::MakeNode(T First, ...)
{
    T Data[D] = {First};
    va_list Args;
    va_start(Args, First);
    for(unsigned i = 1; i &lt; D; i++)
        Data[i] = va_arg(Args, T);
    va_end(Args);
    return Interpolation::Node&lt;T, D&gt;(Data);
}
int main()
{
    using Interpolation::MakeNode;
    std::vector&lt; ::Interpolation::Node&lt;float, 2&gt; &gt; Data;
    Data.push_back(MakeNode&lt;float, 2&gt;(5, 5));
    std::cout &lt;&lt; Data.front().Data[0] &lt;&lt; ' ' &lt;&lt; Data.front().Data[1];
}
</code></pre>
<p>dieser code kompiliert, jedoch bekomme ich einen runtime error:<br />
<a href="http://ideone.com/TPaMLe" rel="nofollow">http://ideone.com/TPaMLe</a></p>
<blockquote>
<p><code>result: runtime error	 time: 0s memory: 2892 kB signal: 4 (SIGILL)</code></p>
</blockquote>
<p>ich kann mir diesen runtime error nicht erklären, ich hab den teil mit der variadik neu geschrieben um allenfällige tippfehler die mir nicht aufgefallen sind auszuschliessen, mit dem selben ergebnis.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341392</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341392</guid><dc:creator><![CDATA[referator]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:08:40 GMT</pubDate></item><item><title><![CDATA[Reply to variadische funktion on Fri, 26 Jul 2013 08:22:29 GMT]]></title><description><![CDATA[<blockquote>
<p>test.cpp: In function ‘Interpolation::Node&lt;T, D&gt; Interpolation::MakeNode(T, ...) [with T = float; unsigned int D = 2u]’:<br />
test.cpp:34:9: warning: ‘float’ is promoted to ‘double’ when passed through ‘...’ [enabled by default]<br />
test.cpp:34:9: note: (so you should pass ‘double’ not ‘float’ to ‘va_arg’)<br />
test.cpp:34:9: note: if this code is reached, the program will abort</p>
</blockquote>
<p>Könnte man durch type traits erschlagen, andererseits sind variadische Funktionen sowieso ziemlich bösartig.<br />
<a href="http://ideone.com/JWa9r0" rel="nofollow">http://ideone.com/JWa9r0</a></p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341395</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341395</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:22:29 GMT</pubDate></item><item><title><![CDATA[Reply to variadische funktion on Fri, 26 Jul 2013 08:23:43 GMT]]></title><description><![CDATA[<p>camper schrieb:</p>
<blockquote>
<blockquote>
<p>test.cpp: In function ‘Interpolation::Node&lt;T, D&gt; Interpolation::MakeNode(T, ...) [with T = float; unsigned int D = 2u]’:<br />
test.cpp:34:9: warning: ‘float’ is promoted to ‘double’ when passed through ‘...’ [enabled by default]<br />
test.cpp:34:9: note: (so you should pass ‘double’ not ‘float’ to ‘va_arg’)<br />
test.cpp:34:9: note: if this code is reached, the program will abort</p>
</blockquote>
<p>Könnte man durch type traits erschlagen, andererseits sind variadische Funktionen sowieso ziemlich bösartig.</p>
</blockquote>
<p>okay, das wusste ich nicht. gut zu wissen.</p>
<p>naja, da mein derzeitiger compiler noch nicht c++11 kompatibel ist und da partionelle funktions-template-spezialisierungen nicht erlaubt sind, stellt sich die frage, wie ich vorgehen soll.</p>
<p>kleine idee:</p>
<pre><code>template&lt;class T&gt;
struct GetClass
{
    typedef T Type;
};
template&lt;&gt;
struct GetClass&lt;float&gt;
{
    typedef double Type;
};
</code></pre>
<p>kann ich das so machen?</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341397</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341397</guid><dc:creator><![CDATA[referator]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:23:43 GMT</pubDate></item><item><title><![CDATA[Reply to variadische funktion on Fri, 26 Jul 2013 08:39:09 GMT]]></title><description><![CDATA[<p>referator schrieb:</p>
<blockquote>
<p>kleine idee:</p>
<pre><code>template&lt;class T&gt;
struct GetClass
{
    typedef T Type;
};
template&lt;&gt;
struct GetClass&lt;float&gt;
{
    typedef double Type;
};
</code></pre>
<p>kann ich das so machen?</p>
</blockquote>
<p>Sicher, löst aber das Problem nicht: Der Aufrufer übergibt (die zweite) 5 immer noch als int. Das dann einfach als double zu verwenden, wird nicht funktionieren.</p>
]]></description><link>https://www.c-plusplus.net/forum/post/2341403</link><guid isPermaLink="true">https://www.c-plusplus.net/forum/post/2341403</guid><dc:creator><![CDATA[camper]]></dc:creator><pubDate>Fri, 26 Jul 2013 08:39:09 GMT</pubDate></item></channel></rss>