c

Style of C API function

I am working on a library that support multiple programming environment such as VB6 and FoxPro. I have to stick with C convention as it is the lowest common denominator. Now I have a question regarding the style. Suppose that the function process input and returns a string. During the process, the error can happen. The current proposed ...

WMI Queries in C?

Is it possible to issue WMI WQL queries in plain C? And if yes, how? ...

Problem in Daylight Saving Time Switch

A program I wrote about four years ago, which gets the date and time as follows: get_the_date_and_time(char *string) { struct tm *now; time_t lt; lt = time(NULL); now = localtime(&lt); sprintf(string,asctime(now)); } It is returning the time an hour late since the switch to Daylight Saving Time. By changing my sy...

How to keep implementation/maintenance costs low in Pro*C?

Having experienced the horror that is Oracle Pro*C, when dealing with dynamically specified columns, and the need for bulk operations (ANSI METHOD 4), I simply must ask: What Ideas/Techniques can you share which makes it easier to develop/test/debug/maintain C and C++ CRUD applications which use Pro*C or Pro*C++? I am specifically int...

What does EPS mean in C?

I have the following code snippet: if (ABS(p43.x) < EPS && ABS(p43.y) < EPS && ABS(p43.z) < EPS) return(FALSE); Which I'm trying to convert to C#. What does "EPS" mean? This code is from http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline3d/ ...

Why do I have to use free on a pointer but not a normal declaration?

Why do I have to use free() when I declare a pointer such as: int *temp = (int*)malloc(sizeof(int)) *temp = 3; but not when I do: int temp = 3; ...

Implementing autosave w/o disruption

I have been hacking on the code for Xournal in order to add auto-save functionality. My initial implementation was very dumb: every 60 or so seconds, do a save. The feature ostensibly works. However, after testing it out for a while, I've noticed that when auto-save runs, the application temporarily freezes up, which is quite annoying i...

zero length arrays vs. pointers

EDIT: apparently some of this isn't allowed/has changed in various C standards. For my own hypothetical benefit, let's pretend we're using gcc test.c with no standard or warning options. In particular I'm looking at the under-the-hood specifics. I've added my current understanding. Am I right? char **c1; //Size for a pointer is al...

Using a sed equivalent in a C program

I have a string input to my program of the form: con*.cc I want this to represent the regular expression, con.*.cc. How can I do this inside a C program? Is there something like sed that I can use? ...

tcp - getting num bytes acked

In standard tcp implementations (say, on bsd), does anybody know if it's possible to find out how many bytes have been ack-ed by the remote host? Calling write() on a socket returns the number of bytes written, but I believe this actually means the number of bytes that could fit into the tcp buffer (not the number of bytes written to th...

Objective C Boolean Array

I need to utilize an array of booleans in objective-c. I've got it mostly set up, but the compiler throws a warning at the following statement: [updated_users replaceObjectAtIndex:index withObject:YES]; This is, I'm sure, because YES is simply not an object; it's a primitive. Regardless, I need to do this, and would greatly appreciate...

Is short-circuiting boolean operators mandated in C/C++? And evaluation order?

Does the ANSI standard mandate logic operators to be short-circuited, in either C or C++? I'm confused for I recall the K&R book saying your code shouldn't depend on these operations being short circuited, for they may not. Could someone please point out where in the standard it's said logic ops are always short-circuited? I'm mostly in...

Character to Integer in C

Is there a way to convert a character to an integer in C? for example, '5' -> 5 thanks. ...

how does array[100] = {0} set the entire array to 0?

How does the compiler fill values in char array[100] = {0};? What's the magic behind it? I wanted to know how internally compiler initializes. Thanks in advances. Looking more such sorts of tricks. ...

why bit-fields for same data types have less in size compared to bit-fields for mix-data types

I am curious to know why bit fields with same data type takes less size than with mixed data types. struct xyz { int x : 1; int y : 1; int z : 1; }; struct abc { char x : 1; int y : 1; bool z : 1; }; sizeof(xyz) = 4 sizeof(abc) = 12. I am using VS 2005, 64bit x86 machine. A bit machine/compiler level answe...

Where can I find a ZwCreateFile example for C++?

I am looking for an example to read an already opened COM port, the only thing that I have found is an application called PORTMON that refers to a method called ZwCreateFile. ...

function pointers callbacks C

Hello, I have started to review callbacks. I found this link: http://stackoverflow.com/questions/142789/what-is-a-callback-in-c-and-how-are-they-implemented which has a good example of callback which is very similar to what we use at work. However, I have tried to get it to work, but I have many errors. #include <stdio.h> /* Is the ...

strlen() on non-null-terminated char string?

Is strlen(const char *s) defined when s is not null-terminated, and if so, what does it return? ...

What is the best method to read a double from a Binary file created in C?

A C program spits out consecutive doubles into a binary file. I wish to read them into Python. I tried using struct.unpack('d',f.read(8)) EDIT: I used the following in C to write a random double number r = drand48(); fwrite((void*)&r, sizeof(double), 1, data); The Errors are now fixed but I cannot read the first value. for an all 0.0...

Request for a simple C code example that shows how a generic or untyped (via void *) array can be used

I'm struggling to create a generic (or untyped) array in C (I'm aware that C++ makes this easier). In a nutshell I want to allocate an array to hold an array of a specific known type (at runtime). In the real implementation it depends on user input. I've been trying to use a enum/struct scenario following the advice found in several Goo...