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
Related Q & A:
- What are natural examples of non-relativizable proofs?Best solution by Theoretical Computer Science
- How do I call an objective-c method?Best solution by Stack Overflow
- What are some examples of motif?Best solution by answers.com
- What are some examples of underground architecture?Best solution by Yahoo! Answers
- What are some examples of direct and indirect job interview questions?Best solution by Quora
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
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.