What are examples of a qualitative smart objective?

What are some examples of code that is identical and valid in C and Objective-C but behaves semantically differently in each language?

  • Objective-C is described as a superset of C, though is it "generally" a superset, or a strict formal superset ? I'm curious if there are small language centric quirks such that there are some instances of code that is also valid C code that behaves semantically differently in Objective-C.

  • Answer:

    One of the complaints about property-access syntax is that it looks the same as structure-access syntax.     foo.bar = baz;     baz = foo.bar; If foo is a pointer to an Objective-C object, each of these translates to a message expression:     [foo setBar:baz];     baz = [foo bar]; If foo is a C structure, then each of them is a structure member access. There is no code that is valid in both languages, with the same type of foo, but means different things. All C code means exactly the same in Objective-C. All Objective-C-specific code (e.g., non-property message expressions) is invalid C. Opportunity for preprocessor-powered hijinks: Write hybrid code that is Objective-C (using objects) on Mac OS X/iOS and plain C (using structures) on other operating systems. You must overcome, or avoid encountering, the problem that the structures cannot be dynamically allocated because the dot operator requires a non-pointer (and dereferencing the pointer would make the code invalid in Objective-C).

Peter Hosey at Quora Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.