c

Compilers and negative numbers representations

Recently I was confused by this question. Maybe because I didn't read language specifications (it's my fault, I know). C99 standard doesn't say which negative numbers representation should be used by compiler. I always thought that the only right way to store negative numbers is two's complement (in most cases). So here's my question: ...

k&r C trouble

This is a quick slightly subjective question I need to ask. In order to become a proficient C programmer, I felt I'd learn C from the k&r. I find the book a little easygoing, difficult to understand sometimes but easygoing on the whole. My question here is, do I have to absoultely do all the exercises (even those that stumped me) to b...

Faster I/O in C

Hi, I have a problem which will take 1000000 lines of inputs like below from console. 0 1 23 4 5 1 3 5 2 56 12 2 3 33 5 ... ... I have used scanf, but it is very very slow. Is there anyway to get the input from console in a faster way? I could use read(), but I am not sure about the no of bytes in each line, so I can not as read() t...

Why does Microsoft's C compiler want the variables at the beginning of the function?

I am currently writing a C (not C++). It seems the Microsoft's C compiler requires all variables to be declared on top of the function. For example, the following code will not pass compilation: int foo(int x) { assert(x != 0); int y = 2 * x; return y; } The compiler reports an error at the third line, saying error C214...

How does inclusion of header file happen?

I have a plain C code with *.c and *.h files in the workspace. I have a header file 1.h declaring some structure as struct my1 { int a; .. .. }my_t; But when i try to declare a variable of type struct my1 in another header file 2.h as follows:- struct my1 variable1; It gives error at this declaration point. Looks like my1 is und...

How is the order of Compilation of source files decided

I have a workspace containing many *.c files, which I compile. (I could use any toolchain say MSVC6.0, or gcc etc) Which source file is compiled first? How is the order of the files to be compiled subsequently decided? ...

Are uninitialized struct members always set to zero?

Consider a C struct: struct T { int x; int y; }; When this is partially initialized as in struct T t = {42}; is t.y guaranteed to be 0 or is this an implementation decision of the compiler? ...

Testing Bits To Create A String - Is there a better approach?

This code works, but I'm wondering if there is a better way to do it. Basically I need to test bits, and write the appropriate character or characters to a string depending on the state of the bit. The spaces are present because the characters will be displayed with a fixed width font and I'd like to keep them from moving around. C or...

Can I use a dll written in C with PHP?

We are interfacing with a piece of hardware developed here, and allowing access via the web. The firmware for this device is written in C, and part of that firmware is about 5000 lines of code that parses huge binary files for config data, compiled to a .dll. Is there any way under heaven that I can access a .dll, written in C, from PH...

typedef enum in Objective C

I don't think I fundamentally understand what a enum is, and when to use it. For example: typedef enum { kCircle, kRectangle, kOblateSpheroid } ShapeType; What is really being declared here? ...

Flush communications handle receive buffer?

In Win32 C is there an API call to flush (dump) the contents of a COM port recieve buffer? I could only find functions to flush the transmit buffers. ...

Need Help Understanding Compilers/HLL->Assembly

I am an electronics student and I have programmed mostly in Assembly. Last night I saw an amazing article that discussed writing a compiler in Ruby. What the author had done was use GCC to peek how the C translates to Assembly. That resonated a lot for me. I could finally see how the C program translated to Assembly.My question/request t...

Bug fixed with four nops in an if(0), world no longer makes sense.

I was writing a function to figure out if a given system of linear inequalities has a solution, when all of a sudden it started giving the wrong answers after a seemingly innocuous change. I undid some changes, re-did them, and then proceeded to fiddle for the next two hours, until I had reduced it to absurdity. The following, inserted...

Implementing A Plugin System in C or C++

What are your tips on implementing a plugin style system? ...

MPI: Locking the stdout -- 1 process at a time?

Hello. I want to print out the content of integer array of each processes. Problem is, it's all cluttered because of race condition. What is the simplest solution? I don't want to debug. I want to show the contents because I'm doing sorting algorithm. So it's useful to show before and after sort. I added this in lock.c: #include <std...

readv(), writev(), WSARecv(), WSASend()

Hi everyone, I hope you can help me out. I'm trying to send packets of 1000 bits across a network via TCP/IP and I was hoping to be able to use the Overlapped I/O technique in both Cygwin and Windows as well. In Cygwin, I am trying to use the "readv() and writev()" function calls to send 1000 bits across while in Windows, I am tryin...

Retrieving joystick name with win32 api

Hi, I have a joystick plugged in. It has a name string "My 50cent Joystick" that shows up if I go to Game Controllers under the Control Panel on Vista. I want to retrieve this string programmatically. After some research I found joyGetDevCaps that can retrieve a lot of information except the name string. Under szPname I get "Microsoft Pc...

Macro questions

On a software project (some old C compiler) we have a lot of variables which have to be saved normal and inverted. Has somebody a idea how i can make a macro like that? SET(SomeVariable, 137); which will execute SomeVariable = 137; SomeVariable_inverse = ~137; Edit: The best Solution seems to be: #define SET(var,value) do { var...

Windows: Overwrite File In Use

I am trying to write a utility that will allow moving files in Windows, and when it finds a file in use, will set that file to be moved on reboot. It seems that MoveFileEx (http://msdn.microsoft.com/en-us/library/aa365240(VS.85).aspx) is the right call for this, however I cannot figure out what error code I'm looking for from GetLastErr...

int issue in g++/mysql/redhat

Hi - I haven't written C in quite some time and am writing an app using the MySQL C API, compiling in g++ on redhat. So i start outputting some fields with printfs... using the oracle api, with PRO*C, which i used to use (on suse, years ago), i could select an int and output it as: int some_int; printf("%i",some_int); I tried to d...