6

I searched for 'copy' in the SL reference and couldn't find anything related.

If I have:

float a[3] = float[3] (1.0,2.0,3.0);
float b[3] = a;

Is b now pointing to a? If I change b[0] would that alter a[0]? If the answer is yes, is there a copy function that I could use to a get a clone of a and not point to it? thanks

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Jeff Saremi
  • 2,674
  • 3
  • 33
  • 57

1 Answers1

4

See GLSL - The OpenGL Shading Language 4.6; 5.8. Assignments; page 114

Assignments of values to variable names are done with the assignment operator (=):

lvalue-expression = rvalue-expression

The lvalue-expression evaluates to an l-value. The assignment operator stores the value of r-value-expression into the l-value and returns an r-value with the type and precision of lvalue-expression.

In glsl there is nothing like a pointer or reference or even a "move" assignment. Values are always copied.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
  • I have same question for hlsl unanswered for quite a long ime https://stackoverflow.com/questions/54041733. It freaks me out why so few people come up with this question as it is quite unobvious and very simple. This unswer is the closest and only thing I found on the Internet about my question and this post had only one upvote. Strange. – Oliort UA Jul 30 '19 at 11:02