OSL Struct SyntaxError I'm trying to create a way to calculate imaginary numbers in OSL using the struct constructor. Here is the beginning of my code:

#include "stdosl.h"

struct complex {
    color r;
    color i;
};

complex test;


According to the documentation, that should create a complex datatype, then initialize a variable named test. Instead, I get these errors:

ERROR: &lt;path-to-file&gt;.osl:8: error: Unknown shader type: complex
ERROR: &lt;path-to-file&gt;.osl:8: error: Syntax error: syntax error
Error: OSL script compilation failed, see console for errors


This seems to indicate a syntax error on line 8, but I can't figure out what is wrong.
You should declare the variable inside a shader

struct complex {
    color r;
    color i;
};

shader node_complex(output float result=0.0)
{
    complex test;
}


This will resolve the compilation error. The issue is that Global variables in OSL are predefined and it is not possible to create custom global variables.

You can use these structs inside shaders and pass it around.