<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; charset=utf-8"><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Also, since you’re defining the array at global scope, the size of it must be a compile time const-expression anyways, so you wouldn’t even need dynamic memory allocation.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Vec3<unsigned char> framebuffer[imageWidth * imageHeight]; <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>would work., instead of using new. That also has the advantage that the linker will more easily catch size overruns. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='border:none;padding:0in'><b>From: </b><a href="mailto:triembed@triembed.org">Jon Wolfe via TriEmbed</a><br><b>Sent: </b>Wednesday, April 22, 2020 11:36 AM<br><b>To: </b><a href="mailto:triembed@triembed.org">Jon Wolfe via TriEmbed</a><br><b>Subject: </b>Re: [TriEmbed] TriEmbed Digest, Vol 83, Issue 15</p></div><p class=MsoNormal><o:p> </o:p></p></div></body></html><html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; "><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I just realized something I’d overlooked. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Your for loop *<b>is</b>* unexpected in your example, it’s outside of any function.<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I just fired up the Arduino and tried my example template code (with the for loop inside of Setup) , and it worked for me. </p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='border:none;padding:0in'><b>From: </b><a href="mailto:triembed@triembed.org">Jon Wolfe via TriEmbed</a><br><b>Sent: </b>Wednesday, April 22, 2020 11:26 AM<br><b>To: </b><a href="mailto:triembed@triembed.org">Alex Davis via TriEmbed</a><br><b>Subject: </b>Re: [TriEmbed] TriEmbed Digest, Vol 83, Issue 15</p></div><p class=MsoNormal><o:p> </o:p></p></div></body></html><html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40"><head><meta http-equiv=Content-Type content="text/html; "><meta name=Generator content="Microsoft Word 15 (filtered medium)"><style><!--
/* Font Definitions */
@font-face
        {font-family:"Cambria Math";
        panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
.MsoChpDefault
        {mso-style-type:export-only;}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style></head><body lang=EN-US link=blue vlink="#954F72"><div class=WordSection1><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Did it compile if you commented out the template stuff and just tried:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>int* foo = new int[42];<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>That would tell you if it was the dynamic array issue vs something not right with the templates. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>I’d bet big money that is not any issue with the compiler not supporting templates, it appears to be basic use of templates, and gcc has supported that for a few decades. <o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>Here is another test, try making your own template class, and attempt the same allocation:<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>template <typename T> class TestVec<o:p></o:p></p><p class=MsoNormal>{<o:p></o:p></p><p class=MsoNormal>public:<o:p></o:p></p><p class=MsoNormal>        TestVec(T t) {}<o:p></o:p></p><p class=MsoNormal>};<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>VecTest<unsigned char> *frameBuffer = new TestVec <unsigned char>[imageWidth * imageHeight];<o:p></o:p></p><p class=MsoNormal>for (uint32_t i = 0; i < imageWidth * imageHeight; ++i) frameBuffer[i] = TestVec <unsigned char>(255);<o:p></o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>By the way, even if “Vec” class is a single byte, your allocation would require 16 *<b>megabytes</b>*. That’s not going to work on Arduino AVR.</p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal>It might even be the case that since the int type on Arduino AVR is 16 bit, and also I think that “size_t” type is unsigned  16 bit. The compiler could be freaking out, not knowing how to handle a number that large for the allocation. I’d try getting it working first with a really small number of array elements. </p><p class=MsoNormal><o:p> </o:p></p><p class=MsoNormal><o:p> </o:p></p><div style='mso-element:para-border-div;border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0in 0in 0in'><p class=MsoNormal style='border:none;padding:0in'><b>From: </b><a href="mailto:triembed@triembed.org">Alex Davis via TriEmbed</a><br><b>Sent: </b>Wednesday, April 22, 2020 11:15 AM<br><b>To: </b><a href="mailto:triembed@triembed.org">triembed@triembed.org</a><br><b>Subject: </b>Re: [TriEmbed] TriEmbed Digest, Vol 83, Issue 15</p></div><p class=MsoNormal><o:p> </o:p></p></div></body></html><br />>    2. Re: C++ class templates in Arduino - problems (Jon Wolfe)<br />>    3. Re: C++ class templates in Arduino - problems (Robert Mackie)<br /><br />Simplifying the program to just this:<br />#include "geometry.h"<br /><br />const uint32_t imageWidth = 4095;<br />const uint32_t imageHeight = 4095;<br /><br /><br />// define the frame-buffer and the depth-buffer. Initialize depth buffer<br />// to far clipping plane.<br />Vec3<unsigned char> *frameBuffer = new Vec3<unsigned char>[imageWidth * imageHeight];<br />for (uint32_t i = 0; i < imageWidth * imageHeight; ++i) frameBuffer[i] = Vec3<unsigned char>(255);<br /><br /><br />// ----------------------------------------------<br />// setup<br />// ----------------------------------------------<br />void setup() {<br />  <br />}<br /><br />// ----------------------------------------------<br />// main loop<br />// ----------------------------------------------<br />void loop() {<br />    <br />}<br /><br />still results in the same compile error. Moving the new line into the include gives the same error.<br /><br />Alex<br /><br /><br />-- <br />"The theater of noise is proof of our potential."<br />|\ |  (¯  \/ |¯\  |V| |\ ¯|¯ |¯) | \/ | | | |¯\ (¯   /¯  /\ |V|<br />|-||_ (_  /\ |_/ @| | |-| |  | \ | /\ |^| | |_/ (_ . \_  \/ | |<br /><br />You won't find me on Facebook.<br /><br />_______________________________________________<br />Triangle, NC Embedded Computing mailing list<br /><br />To post message: TriEmbed@triembed.org<br />List info: http://mail.triembed.org/mailman/listinfo/triembed_triembed.org<br />TriEmbed web site: http://TriEmbed.org<br />To unsubscribe, click link and send a blank message: mailto:unsubscribe-TriEmbed@bitser.net?subject=unsubscribe<br /><br />