Jump to content

C Style Vs. C++ Style?


Recommended Posts

I wonder what the difference between the "old" C style and "new" C++ style of type casting?

I've tried to do

vector var = (vector)pcfilter...

and vcc said that it can't determine which version to use. If I change the code to

vector var = vector(pcfilter...)...

all is okay. So there is the difference... :huh:

Link to comment
Share on other sites

I wonder what the difference between the "old" C style and "new" C++ style of type casting?


Unlike C++ (but like RenderMan SL), VEX uses the return type as part of the signature. This can create unresolvable type problems

   Cf = random(noise(P));

This code should generate a warning from vcc since it's impossible to figure out whether the noise() function should return a float, vector or vector4.

The C++ style of casting is used to specify the return type explicitly.

   Cf = random( vector(noise(P)) );

The C style of casting is implemented as a type conversion operation.

If you inspect the VEX assembler of the two types of

   Cf = random(  (vector) noise(P));

You'll still get the warning, and you should see that the noise() function generates a floating point value which is then converted to a vector. This is very different than the noise() function generating a vector result by itself.

However, since the C++ type-casting style is used for explicit return code specification, it can't really be used for casting one type to another. You have to use the C style.

	int	ival = (int)(s*4.0);

A very subtle difference, but a potentially important one.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...