c

What's the "condition" in C interview question?

What is the answer to this C question: What's the "condition" so that the following code snippet prints both HelloWorld ! if "condition" printf ("Hello"); else printf("World"); ...

Cocoa tips for PHP developers?

I'm a PHP developer, and I use the MVC pattern, and object oriented code. I really want to write applications for the iPhone, but to do that I need to know Cocoa, but to do that I need to know Objective-C 2.0, but to do that I need to know C, and to do that I need to know about compiled languages (versus interpreted). Where should I be...

What are good projects to develop C skills?

I wondered what projects would be good to develop C skills? I can think of many projects to develop C#, F#, IronRuby, etc. skills as the .net framework provides ample opportunity for any number of different applications; however I'm less knowledgable about the libraries provided with C, and the possible apps one can develop which are act...

How do I get the assembler output from a C file in VS2005

I think the file that is produced is an .asm file, any idea how to produce this in Visual Studio when you do a build? ...

How do I list the symbols in a .so file

How do list the symbols being exported from a .so file. If possible, I'd also like to know their source (e.g. if they are pulled in from a static library). I'm using gcc 4.0.2, if that makes a difference ...

Byte level length description

I have a protocol that requires a length field up to 32-bits, and it must be generated at runtime to describe how many bytes are in a given packet. The code below is kind of ugly but I am wondering if this can be refactored to be slightly more efficient or easily understandable. The problem is that the code will only generate enough by...

Compiler Error C2143 when using a struct

I'm compiling a simple .c in visual c++ with Compile as C Code (/TC) and i get this compiler error error C2143: syntax error : missing ';' before 'type' on a line that calls for a simple struct struct foo test; same goes for using the typedef of the struct. error C2275: 'FOO' : illegal use of this type as an expression ...

Print Odd-Even numbers using signals

The problem is to print natural nos. 1,2,...n such that the parent process prints all odd numbers and child all even numbers using POSIX signals. Output should be: Parent : 1 Child : 2 Parent : 3 and so on...any suggestions? ...

How to divide two 64-bit numbers in Linux Kernel?

Some code that rounds up the division to demonstrate (C-syntax): #define SINT64 long long int #define SINT32 long int SINT64 divRound(SINT64 dividend, SINT64 divisor) { SINT32 quotient1 = dividend / divisor; SINT32 modResult = dividend % divisor; SINT32 multResult = modResult * 2; SINT32 quotient2 = multResult / divisor; SI...

Linux: What is the best way to estimate the code & static data size of program?

I want to be able to get an estimate of how much code & static data is used by my C++ program? Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime? Will objdump & readelf help? ...

Writing cross-platform apps in C

What things should be kept most in mind when writing cross-platform applications in C? Targeted platforms: 32-bit Intel based PC, Mac, and Linux. I'm especially looking for the type of versatility that Jungle Disk has in their USB desktop edition ( http://www.jungledisk.com/desktop/download.aspx ) What are tips and "gotchas" for this ty...

add preddefined data for typedef enums in c

What is the best approach to define additional data for typedef enums in C? Example: typedef enum { kVizsla = 0, kTerrier = 3, kYellowLab = 10 } DogType; Now I would like to define names for each, for example kVizsla should be "vizsla". I currently use a function that returns a srting using a large switch block. ...

How do I execute a file in Cygwin?

I created a C file in Eclipse on Windows and then used Cygwin to navigate to the directory. I called gcc on the C source file and a.exe was produced. How do I execute a.exe in the Cygwin shell? ...

Alignment restrictions for malloc()/free()

K&R (2nd ed.) and other C-language texts I have read that cover implementation of a dynamic memory allocator in the style of malloc() and free() usually also mention, in passing, something about alignment restrictions. Apparently certain platforms restrict how you can store and address certain values, requiring, for example, integers to ...

What is the fastest way to swap values in C?

I want to swap two integers, and I want to know which of these two implementations will be faster: The obvious way with a temp variable: void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } Or the xor version that I'm sure most people have seen: void swap(int* a, int* b) { *a ^= *b; *b ^= *a; *a ^=...

Equivalent to StAX for C

I've used the StAX API in Java quite a bit, and find it quite a clean way of dealing with XML files. Is there any equivalent library I could use for performing similar processing in C? ...

(C) How do I determine the size of my array?

i.e., the number of elements the array can hold? ...

Auto defines in C editors... Why?

When I let Eclipse create a new file (.c or .h file) in a C project the editor always auto creates a #define at the top of the file like this: If the file is named 'myCFile.c' there will be a #define at the start of the file like this #ifndef MYCFILE_C_ #define MYCFILE_C_ I have seen other editors do this as well (Codewright and Slik...

Why does Splint (the C code checker) give an error when comparing a float to an int?

Both are mathematical values, however the float does have more precision. Is that the only reason for the error - the difference in precision? Or is there another potential (and more serious) problem? ...

Why does this C code produce a double instead of a float?

celsius = (5.0/9.0) * (fahr-32.0); Is it just a development choice that the C developers decided upon or is there a reason to this? I believe a float is smaller than a double, so it might be to prevent overflows caused by not knowing what decimal format to use. Is that the reason, or am I overlooking something? ...