Is there a way to forbid the usage of potential unsafe functions like malloc, _memcpy and others from being used by the clang compiler when compiling objective c code?
Related
Wikipedia says it has a garbage collector, yet I never heard of any JIT compiler for it (e.g. JRE, CLR, ect). Does it compile at run-time or compile-time?
D is compiled (at compile time, natch).
D has an optional garbage collector. GC is orthogonal to static/dynamic compilation.
There are other examples of GCed, static languages without JIT compilation, like Eiffel.
I was reading the clang documentation on reference counting, which says that “ By default in Objective-C, ARC is not exception-safe”. It proceeds to say:
A program may be compiled with the option -fobjc-arc-exceptions in order to enable these, or with the option -fno-objc-arc-exceptions to explicitly disable them, with the last such argument “winning”.
In Objective-C++, -fobjc-arc-exceptions is enabled by default.
I was intrigued. Are there any other compiler options whose default change between Objective-C and Objective-C++?
Complementary question: what is difference between compiling purely Objective-C code with clang in Objective-C++ mode (*.mm files) rather than in Objective-C mode only (*.m)?
Best way is to log what clang will output from all those c language
here's some of what i have got from a obj-c++ compilation
clang++ -fobjc-arc main.mm -v
/.../
-fblocks
-fobjc-runtime=macosx-10.7.0
-fobjc-dispatch-method=mixed
-fobjc-default-synthesize-properties
-fobjc-arc
-fobjc-arc-cxxlib=libstdc++
-fobjc-arc-exceptions
-fobjc-exceptions
-fcxx-exceptions
-fexceptions
-fdiagnostics-show-option
-fcolor-diagnostics
/.../
As you can see those output can vary depending from where you compile it. But some of them are constants.
You should try on different c families files in order to determine what the default option are for these respective.
Hope it will help you.
To answer the second part of your question: If you compile files in Objective-C mode rather than Objective-C++ mode, you get better support from the Static Analyzer [1]. I believe the compiler will also generate more accurate warnings in general (without using the Static Analyzer), but I cannot find/remember the source of that information.
I have the source code for a video decoder which is written in C.
The code was successfully compiled and executed on MAC terminal (which uses GCC compiler). Now I'm trying to create an application on Xcode with the same source code. Only the GUI for the application is written in Objective-C.
When I tried to execute on Xcode (which uses LLVM compiler), I'm getting a lot of errors in the C code.
The only other compiler option that Xcode provides is LLVM GCC 4.2. I compiled using that and found that it is not able to recognize the code written in Objective-C.
Is there any compiler that can be used for both Objective-C and C?
Can GCC 4.2 compiler be used for compiling Objective-C code?
How to tell Xcode to compile using GCC 4.2 compiler?
Kindly help. Thanks in advance!
Both LLVM and GCC can be used to compile C, C++ and Objective-C code.
My guess is that some compiler flags are set incorrectly.
Objective-C is a strict superset of ANSI C, so any compiler that can compile Objective-C code can also compile (ANSI) C code. If your library does not use standard C, then you might run into problems.
The same is true for Objective-C++, which is a strict superset of C++.
If, like in your case, you have a conflicting typedef in your header file, you can use conditional compilation to hide the typedef when compiling Objective-C code:
#ifndef __OBJC__
typedef unsigned char BOOL;
#endif
I had this declaration.
- (BOOL)getNHPData:(REMOTE_MESS_ID)msgId withEvent:(RSEvent*&)pEvent;
I tried with RSEvent** also but i'm getting this error for 2 times
Expected ')' before RSEvent
Why is it so.
Objective-C is a superset of the C language and does not have references. If you want to use C++-style references in Objective-C, you must compile as Objective-C++ (as you might expect, Objective-C++ is a superset of C++). Use the .mm extension to automatically use the Objective-C++ in Xcode.
If the method in question is a public API that will be consumed from Objective-C, I would highly recommend using a pointer-to-pointer (RSEvent**) instead of a pointer reference. Using Objective-C++ in a header "infects" clients with Objective-C++ (unless you're very careful). Objective-C++ takes much longer to compile that Objective-C and you will eventually run into the inevitable C vs. C++ incompatibilities. Standard practice is to hide Objective-C++ from public APIs whenever possible.
I personally have never had much success in c++ or obj-c with pointer references, if I need that kind of functionality, I usually just use a pointer pointer like this:
some function()
{
RSEvent *pEvent = new RSEvent();
[self getNHPData:DEFAULT_MSG_ID withEbvent:&pEvent];
}
- (BOOL)getNHPData:(REMOTE_MESS_ID)msgId withEvent:(RSEvent**)pEvent
{
//Do some stuff
}
g++ compiler complains about conversions between related types (from int to enum, from void* to class*, from const char* to unsigned char*, etc.). Compiler handles such convertions as errors and won't compile furthermore. It occurs only when I compile using Dev-C++ IDE, but when I compile the same code (using the compiler which Dev-C++ uses) such errors (even warnings) do not appears.
How to mute errors of such types?
I suspect that in one case you are compiling your code as C and the other as C++. In C++, there is no implicit conversion from void * to any other type of pointer, and a C++ compiler which did not diagnose this as an error would be broken. You need to supply more details of how you are compiling your code.
Also, DevC++ is a pretty awful piece of code. It's buggy and no longer being actively developed, as well as being butt-ugly. You should seriously consider switching to a more modern and capable IDE, such as Code::Blocks.
All of your implicit conversions are disallowed in standards conforming C++. G++ is simply enforcing these rules.