Thread: C/C++ Type Safety

  1. #1
    Registered User
    Join Date
    Nov 2006
    Posts
    61

    C/C++ Type Safety

    C++ uses type-safe I/O. Each I/O operation is executed in a manner sensitive to the data type. If an I/O member function has been defined to handle a particular data type, then that member function is called to handle that data type. If there is no match between the type of the actual data and a function for handling that data type, the compiler generates an error.

    i. Can u give code snippet where C++ compiler gives error when there is data mistmatch between function call and actual input data passed?

    ii. Also give examples of C which shows C is type unsafe?

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Edit: removed code. This appears to be a homework question. Show code illustrating your understanding.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Duh, what else could start with "Give examples..." :P

  4. #4
    C++まいる!Cをこわせ!
    Join Date
    Oct 2007
    Location
    Inside my computer
    Posts
    24,654
    No. No. No. No. You do not just come here and dump the question on us.
    You have to make an effort on this one first. It is YOUR homework, not ours.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  5. #5
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    A teacher asks his/her students to give examples of C/C++ type safety.

    i. Can u give a homework question that the teacher might ask.

    ii. Also give examples of where it might be unsafe to post such questions?
    "I am probably the laziest programmer on the planet, a fact with which anyone who has ever seen my code will agree." - esbo, 11/15/2008

    "the internet is a scary place to be thats why i dont use it much." - billet, 03/17/2010

  6. #6
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by cpjust View Post
    A teacher asks his/her students to give examples of C/C++ type safety.

    i. Can u give a homework question that the teacher might ask.

    ii. Also give examples of where it might be unsafe to post such questions?

  7. #7
    Registered User
    Join Date
    Nov 2006
    Posts
    61
    Friends, you have misunderstood me...I am not a student. I am trying to understand C++ in deep so requesting you to share a knowledge if you can.

  8. #8
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Quote Originally Posted by forumuser
    I am trying to understand C++ in deep so requesting you to share a knowledge if you can.
    That implies that you are a student of C++, and presumably also of C since your question is comparative and posted in the C programming forum

    Anyway, where did you get this paragraph from?
    C++ uses type-safe I/O. Each I/O operation is executed in a manner sensitive to the data type. If an I/O member function has been defined to handle a particular data type, then that member function is called to handle that data type. If there is no match between the type of the actual data and a function for handling that data type, the compiler generates an error.
    If it is from a book, the book should have elaborated on the statement. For example, consider what happens if you define your own class and then try to use the overloaded operator<< to print it, without having defined such an operator or having provided any suitable implicit conversions.

    For C, consider how printf might be used.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  9. #9
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by forumuser View Post
    Friends, you have misunderstood me...I am not a student. I am trying to understand C++ in deep so requesting you to share a knowledge if you can.
    I don't think you understand. Some of us own Deitel and Deitel's book; some of us used it in our programming classes, some of us use to teach from now. I haven't used the newer editions much, but I know of their existence, and I know how to search. If nothing else you can give book and page, so that we don't add "Plagiarist" behind your name. Since you appear to have only gotten to the second paragraph of the chapter (chapter 26 of the fifth edition of C: How to Program by above authors) it might behoove you to move forward.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. LDAP Query
    By Travoiz in forum C++ Programming
    Replies: 0
    Last Post: 08-13-2009, 02:58 PM
  2. GUI Type Scope and Instantiation
    By n00b3 in forum Windows Programming
    Replies: 3
    Last Post: 06-12-2008, 01:47 AM
  3. Replies: 0
    Last Post: 03-20-2008, 07:59 AM
  4. Errors
    By Rhidian in forum C Programming
    Replies: 10
    Last Post: 04-04-2005, 12:22 PM
  5. gcc problem
    By bjdea1 in forum Linux Programming
    Replies: 13
    Last Post: 04-29-2002, 06:51 PM