<html><head><base href="x-msg://2973/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><div>On Sep 9, 2010, at 4:23 AM, Dominic Laflamme wrote:</div><blockquote type="cite"><span class="Apple-style-span" style="border-collapse: separate; font-family: Helvetica; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: normal; orphans: 2; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px; -webkit-border-horizontal-spacing: 0px; -webkit-border-vertical-spacing: 0px; -webkit-text-decorations-in-effect: none; -webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; font-size: medium; "><div class="hmmessage" style="font-size: 10pt; font-family: Tahoma; ">I am porting a bunch of GLSL code over to LLVM and am wondering how I can setup constructors for a certain type.<span class="Apple-converted-space"> </span><br><br>example:<br><font face="Courier New"><br></font><font face="Courier New"><snip></font><font face="Courier New"><br></font><blockquote><font face="Courier New">typedef float float4 __attribute__((ext_vector_type(4)));</font><br><br><font face="Courier New">float4 float4(float r, float g, float b, float a )</font><br><font face="Courier New">{</font><br><blockquote><font face="Courier New">float4 ret = {r,g,b,a};</font><br><font face="Courier New">return ret;</font><br></blockquote><font face="Courier New">}</font><br><br><font face="Courier New">float4 float4(float r, float g, float b )</font><br><font face="Courier New">{</font><br><blockquote><font face="Courier New">float4 ret = {r,g,b,1.0};</font><br><font face="Courier New">return ret;</font><br></blockquote><font face="Courier New">}</font><br></blockquote><font face="Courier New"></snip></font><br><br>Of course this wont work since the function are using the same name, but any idea how I can setup these types of constructors? Should I declare float4 as a struct and overload the constructors? Can the ext_vector_type extension provide some help?<br></div></span></blockquote><div><br></div>In C++, you could certainly just make float4 a class that wraps a vector and has an implicit conversion to vector type.  Alternatively, if you're willing to use different function names, you can just make these overloaded functions.  Otherwise I don't think there's a reasonable solution short of inventing a crazy new language feature.</div><div><br></div><div>It's not unreasonable for us to support direct-initialization of vector types a la 'float4(a,b,c,d)' as a generic form of vector initialization in C++, but obviously that wouldn't extend to the three-argument version.</div><div><br></div><div>John.</div></body></html>