what is #pragma

So I have been trying to figure out what #pragma does. It looks like it calls some libraries but I am not sure. If it is calling libraries, what are available libraries for use and what do these libraries do?

#pragma strict
#pragma implicit
#pragma downcast

Thanks in advance everyone!

1 Answer

1

pragma is a pre-compiler directive. ie it tells the compiler what to do or how to behave.

eg #strict - “be uptight when you compile this schizzle bro!”

how are they helpful in optimizing?

by being strict. they won't allow you to do as dirty code. e.g. when defining a variable without #pragma you can leave out the typing and unity will figure out what the variable 's supposed to be when you use it. But the 'figuring out'-part can take a lot of resources. That's why it's considered bad habit / dirty code to not always type stuff. With #pragma you must tell of what type the variable will be and it will give you an error if you don't comply. Greetz, Ky.

Greta, now I now... the new version of MonoDevelop includes #pragma strict on all new scripts. This will keep me on my toes ;-)

It's Unity 3.5 that includes #pragma strict for new scripts, not MonoDevelop.

Ah, makes sense... since I was opening it through Unity ;-)