When should I use #ifdef instead of if()? [closed] - ios

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
When working in Objective-C, when is it appropriate to use preprocessor directives like
#ifdef, #if, #ifndef, and #define instead of statements like if() and switch()?

Preprocessor directives like #ifdef, etc. are only valid at compile time. They are not able to make decisions or loops at runtime. They simply regulate what gets compiled and what not.
They are totally useless at runtime. They serve a totally different purpose.

These are all part of the C language, there's nothing specific to Objective-C here.
Most of the time in your program logic you're going to be using switches, if-elses, fors, whiles, etc. This applies to C, C++, Objective-C and other C-style languages.
Preprocessor directives are evaluated at compile-time, and so only the preprocessor/compiler is interested in that logic. Your actual program doesn't deal with any of this. You're not going to use directives much except for stuff like architecture differences, compile-time constants, macros and so on.

Related

How do include a .c file to my ios app? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I have file.c file that I want to add to my ios app. I renamed it to file.m, rename the main() to main2() and included it in my project in xCode. It compiles fine but how do I run main2()?
Could someone please explain this in detail? Thanks.
More likely than not, the main of the original C program is going to try and set up a processing loop or otherwise wait for some kind of input and then try to process it.
You aren't going to be able to simply embed one entire program in another and expect it to work unmodified. You'll need to understand how the second program works and then integrate that functionality into the first. Without seeing the implementation of your second main, it is impossible to say more.
You have to call main2() somewhere in your main source file. main() is the entry point for C programs, so if you rename main() to something else, you will have to call it manually.

complex numbers [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 9 years ago.
I am working on a math project.I need a programming language that allows me to evaluate users input.
Like Multiplying 2 complex numbers: I can't use a regular expression since there are many possibilities( I want to include all the steps of calculation.)
You could use Scheme, it's a nice Lisp-like language that has built-in support for complex numbers. Also, since in Scheme data is code, it is really easy to turn user input into executable code.
Chicken Scheme is a popular variant.
Other popular languages with built-in complex number support are:
R: use i as suffix for imaginary numbers. (1+2i)^2 returns -3+4j.
Python: use j as a suffix for imaginary numbers. (1+2j)**2 returns (-3+4j).
Ruby: use the Complex class.
C: include complex.h and use I as the imaginary unit. See also How to work with complex numbers in C?

Can I use some method to get the variable name? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I creat a instance of a class. Can I use some method to get the variable name, then I print out it? I just want this when I do some test project. I think I really mean is the variable name.
Unfortunately, no, you can't.
Object instances don't have names. Classes have names. Methods have names. Properties have names. But object instances don't. Variables have names, but they're not unique to instances, and you don't have access to that programmatically, anyway.
If you just invoke the description method, you'll generally get a little something to identify the instance, but it's not a name.
UIView objects have a numeric tag property, so for those you can set that property and identify your controls that way.
property_getAttributes is part of the Objective-C runtime, as described here http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Introduction/Introduction.html#//apple_ref/doc/uid/TP40008048-CH1-SW1.
If you want to gain some kind of introspection about ObjC classes, it is the way to go. I don't think this is unstable, since the Objective-C runtime itself is quite stable. Furthermore there is an official guide (see link above) so you can trust it to be as stable as any other official Apple API.

Effort to emulate Rtti.pas to Delphi versions prior to D2009 resource needed [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I'm looking for Delphi resources related to any effort to emulate hopefully a substantive subset of the new Rtti.pas unit like ThorRtti.
Edit:
I edited the initial post (header,body and tag) because using backport is misleading and not appropriate for the post.
ThorRtti tried to mimick the Rtti.pas in Delphi 2010.
I just need a direction to go (URLs).
I don't believe what you are hoping to do is viable. The modern RTTI in Delphi is supported by the compiler. As I understand it the compiler writes a lot of extra information into the executable that the RTTI unit relies upon. Older compilers don't do that.

How to combine multiple languages in a single project? [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Is it possible, for instance, to use functions of a C++ library in another language like Java or Ruby? Can a single application be programmed using separated languages? How?
Yes, it is quite possible to create a program that uses multiple languages. Here is a post for using C++ from Ruby. As for Java, you'll want to look at the Java Native Interface.
A program can be coded using different languages either by inline code (e.g., Assembly language in a C/C++ program, or MATLAB code inside of LabVIEW blocks). Or, by calling external library code (e.g., C# interoperability with C/C++ libraries).
Hope that's helpful!
Yes, it is possible to embed C/C++ code in another language. For example, take a look at SWIG:
SWIG is a software development tool that connects programs written in C and C++ with a variety of high-level programming languages. SWIG is used with different types of target languages including common scripting languages such as Perl, PHP, Python, Tcl and Ruby.

Resources