CS 330 Lecture 21 – Weak Typing in C


  • what ?s
  • weak typing examples
    • array allocation
    • big endian
    • is negative check for floats
    • unions
  • “polymorphism” in C


  • Read chapters 1 and 2 of Learn You a Haskell for a Great Good! (Use the free online version.) On a 1/4 sheet, answer these questions:
    • What are two ways we can express the integer division of 9 divided by 5?
    • Write an expression for the successor of the sucessor of character 'z'. Also write the value.
    • What can you say about the operand types that function : expects? Function ++?
    • Define a function named countreps that takes in a count and a number. It returns a list with count instances of number preceded by the count. For example, countreps 3 10 yields [3, 10, 10, 10].


Today we’ll look to some examples of weak typing in C, in which we undermine the type system to do some sometimes perfectly reasonable things. We’ll see why arrays traditionally couldn’t be allocated on the stack via consts, how to do a runtime check for the endianness of a processor, how we can check the negativity of a float, and how one might support a limited form of polymorphism for data structures.



Leave a Reply

Your email address will not be published. Required fields are marked *