Jump to content
  • Advertisement
Sign in to follow this  
derek7

static type safety

This topic is 4506 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

what is type safety? why is it so important? I guess it just a compiler detect technology, it just make thing under control.

Share this post


Link to post
Share on other sites
Advertisement
Typ safety is basically a language feature to prevent certain forms of erroneous or undesirable program behavior (called type errors). This enforcement can be static, catching potential errors at compile time, or dynamic, associating type information with values at run time and consulting them as needed to detect imminent errors, or a combination of both.

Share this post


Link to post
Share on other sites
I will answer using a small example: linked list in C, where you store your data using void* pointers. Since the compiler has no possibility to tell what is the real type of you data, you can handle it the way you want - either correctly or incorrectly.

Another example involve the ellipsis construction: for example, using printf(), the data type is deduced from the format string. If you feed printf() with an integer param where it waits for a string, you'll fool it and your program will crash.

These are two example where static type safety would have been useful. Type-safe code is built to enforce the use of the correct data type at compile time, in order to avoid type deduction at run-time - because if run time type deduction fails, your program is likely to crash.

Regards,

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!