c

Printf the current address in C program

Hello Imagine I have the following simple C program: int main() { int a=5, b= 6, c; c = a +b; return 0; } Now, I would like to know the address of the expression c=a+b, that is the program address where this addition is carried out. Is there any possibility that I could use printf? Something along the line: int main() { int a=5, ...

is the use of varargs in a C API a Good Idea(tm)

I am writing an API for use outside our company, it updates a LOT of different fields in a structure. I could help the addition of future fields by making the update function variadic: update(FIELD_NAME1, 10, FIELD_NAME2, 20); then later add FIELD_NAME3 with out changing any existing calls: update(FIELD_NAME1, 10, FIELD_NAME2, 20...

Serial Port Communication Issues (C code)

I recently tried to get access to a serial communication using a Bluetooth usb dongle. I used the C code below, and keep getting error 5, which is “Access denied”. I am the administrator for the system (which seemed to be the common solution to this problem on the forums) and no other application is accessing the same port I am using (al...

C Timer Callback

Interested in something similar to JavaScript setTimeout in C on both UNIX and Windows. Basically, I want: start_timer(&function_pointer, int time_in_secs) or as close to that as I can get. Also, something similar to setInterval would be nice (where it calls the callback every n seconds), but that can be implemented using setTimeout...

calling a DLL made in VB6 from C

Okay, this one is the reverse of the last question I struggled with... I feel like I'm sooo close to getting it but it's just not working. Before, I was trying to compile a DLL in C, and then call it from VB, but I realized that's not really what I want (I want the program to be written in C, while using a VB frontend, not the frontend b...

If you add extra data space to a DialogBox class be accessed by GetWindowLongPtr, should you add DLGWINDOWEXTRA to access this extra space?

When creating a window class for use with a DialogBox you need to add DLGWINDOWEXTRA to cbWndExtra. If you add extra data space to a DialogBox class be accessed by GetWindowLongPtr, should you add DLGWINDOWEXTRA to access this extra space? (I'll confess that I think I know the answer, and that way the code doesn't break. But, I want to...

gcc: Enabling debug symbols in shared library

I am creating a shared library using gcc and suspect that there may be some memory leaks from the shared library. To debug, I need to enable debug symbols when creating the shared library. To build, I am using gcc -g ... [-g is for enabling debug information] But the library [.so file] size is not changing for both -g, and without -g. B...

How can I get the best accurate result?

Given: unsigned int a, b, c, d; I want: d = a * b / c; and (a *b ) may overflow; also (b/c) may equal zero and give less accuracy. Maybe a cast to 64-bits would get things to work, but I want to know the best way to get the most accurate result in d. Is there any good solution? ...

How to export a struct definition from a native C .dll for use in C#

I know how to extern methods in the .dll, how do I extern structs? I want to create a C method such as extern __declspec(dllexport) myStructure getStruct(); where myStructure is something like typedef struct { int A; int B; char C; } myStructure; How can I call getStruct() from a piece of C# code without first defining th...

How to find the difference between two times in c?

Hi my first time is 12:10:20 PM and second time is 7:10:20 Am of the same day how can i find diff b/w them?? My idea is convert all the time to seconds and find the difference again convert to time is it good Approch r anything else?? ...

How do languages such as Python overcome C's Integral data limits?

While doing some random experimentation with a factorial program in C, Python and Scheme. I came across this fact: In C, using 'unsigned long long' data type, the largest factorial I can print is of 65. which is '9223372036854775808' that is 19 digits as specified here. In Python, I can find the factorial of a number as large as 999 w...

Automated field re-ordering in C structs to avoid padding

I've spent a few minutes manually re-ordering fields in a struct in order to reduce padding effects[1], which feels like a few minutes too much. My gut feeling says that my time could probably be better spent writing up a Perl script or whatnot to do this kind of optimization for me. My question is whether this too is redundant; is the...

C Programming: difference between ++i and i=i+1 from an assembler point of view?

This was an interview question. I said they were the same, but this was adjudged an incorrect response. From the assembler point of view, is there any imaginable difference? I have compiled two short C programs using default gcc optimization and -S to see the assembler output, and they are the same. ...

Difference between n = 0 and n = n - n

When I read this question I remembered someone once telling me (many years ago) that from an assembler-point-of-view, these two operations are very different: n = 0; n = n - n; Is this true, and if it is, why is it so? EDIT: As pointed out by some replies, I guess this would be fairly easy for a compiler to optimize into the same th...

Creating a wrapper for a C library in Python

I'm trying to create a wrapper of my own for FLAC, so that I can use FLAC in my own Python code. I tried using ctypes first, but it showed a really weird interface to the library, e.g. all the init functions for FLAC streams and files became one function with no real information on how to initialize it. Especially since it wants a refer...

How to convert a string to character array in c (or) how to extract a single char form string?

Hi I need to convert a string to char array in c? How can i do this or atleast tell me how to extract a single char from string as incremental in next ??? Thanks in advance ...

How can I get the size of an array in C / Objective-C?

I have this array: unsigned char* data = CGBitmapContextGetData(cgctx); then I tried to get the size with sizeof(data), but that will return me a nonsense-value of 4. data holds a big amount of information. That can't be just 4 ;) I even get information at data[8293] ... so ... not 4 elements at all. ...

How to convert char to integer in C?

Possible Duplicates: How to convert a single char into an int Character to integer in C Can any body tell me how to convert a char to int? char c[]={'1',':','3'}; int i=int(c[0]); printf("%d",i); When I try this it gives 49. ...

Log the REQUEST_URI variable when php is set to log to syslog.

This is the source code of php_log_err. I would like to modify it to be able to log the variable _SERVER["REQUEST_URI"] /* {{{ php_log_err */ PHPAPI void php_log_err(char *log_message TSRMLS_DC) { FILE *log_file; char error_time_str[128]; struct tm tmbuf; time_t error_time; /* Try to use the spe...

Writing & compiling a C program under Windows XP?

Hi, This is an absolute beginner's question, but per the latest podcast, I understand that no question is too newbie. I have 0 programming experience and I want to learn C, so I'm starting the K&R book. I am using a Windows XP laptop, and I am planning on using Notepad++ to write, and Code::Blocks to compile. Here's my question: once...