c

How to serialize the GMP mpf type?

It seems that GMP provides only string serialization of the mpf (floating point) type: mpf_get_str(), mpf_class::get_str() The mpz (integer) type has an additional interface for raw bytes: mpz_out_raw() http://gmplib.org/manual/Function-Index.html Am I missing something? Does anyone know of another library that can serialize GMP flo...

How to keep one of my application windows on top of the other windows of the same application?

I have a Motif-based notepad-like legacy application. I would like the modeless "Find/Replace" dialog (which is a Motif TopLevelShell) to always stay on top of the other windows of my application, but not on top of other applications. I don't see any Motif-specific setting to do this. KDE allows me to set window-specific behavior, but ...

Is there any C standard for microcontrollers?

Hi, I just want to ask, is there any special C standard for MCU? I ask because so far when I programmed something under Windows OS, it doesn´t matter which compiler I used. If I had compiler for C99 I knew what I can do with it. But recently I started to program in C microcontrollers, and I was shocked, that even its still C in its bas...

?: ternary conditional operator behaviour when leaving one expression empty

Hi, I was writing a console application that would try to "guess" a number by trial and error, it worked fine and all but it left me wondering about a certain part that I wrote absentmindedly, The code is: #include <stdio.h> #include <stdlib.h> int main() { int x,i,a,cc; for(;;){ scanf("%d",&x); a=50; i=100/a; for(...

How to avoid writing multiple versions of the same loop

Inside a large loop, I currently have a statement similar to if (ptr == NULL || ptr->calculate() > 5) {do something} where ptr is an object pointer set before the loop and never changed. I would like to avoid comparing ptr to NULL in every iteration of the loop. (The current final program does that, right?) A simple solution woul...

Turbo C time resolution up to milliseconds

The clock_t implications in time.h released with Turbo C++ v1.01 are good only up to 0.0545XX seconds, meaning any timing I want to do with higher precision is impossible with that library. I was wondering if anyone knew a good library or method available to elder TurboC++ that I could use instead of time.h calls for better precision? ...

Why Does GCC Throw Errors About Unspecified Options?

When I run the following command from a makefile on 64-bit Red Hat Enterprise Linux 5.0 using GCC 4.2.3: gcc -c -ansi -pedantic -O0 -fPIC -I. -I.. -Iheader_files/include "source_file.c" I get the following error: cc1: error: unrecognized command line option "-lang-c" Superficially, the problem is that "-lang-c" is no longer a valid...

How can i match each /proc/net/tcp entry to each opened socket?

I salute you, StackOverflow gurus ;) I'm trying to parse socket info from /proc/net/tcp and while I can identify some fields, such as memory addresses or send queue use, I can't find how each entry is bound to its socket descriptor. E.g., with this data: 1: 5922140A:E459 D5C43B45:0050 01 00000000:00000000 00:00000000 00000000 1000 ...

the child process exited normally even if I sent a SIGABRT to it

I was trying some process operations like fork()ing and exec()ing I tried this Example which in it the parent wait()s his child to return and test if his child ended normally (by exit()ing or return to his caller) or abnormally (receiving Signal like SIGABRT) #include<stdio.h> #include<stdlib.h> #include<sys/types.h> #include<unistd.h> ...

Is there a bit-equivalent of sizeof() in C?

Sizeof() doesn't work when applied to bitfields: # cat p.c #include<stdio.h> int main( int argc, char **argv ) { struct { unsigned int bitfield : 3; } s; fprintf( stdout, "size=%d\n", sizeof(s.bitfield) ); } # gcc p.c -o p p.c: In function ‘main’: p.c:5: error: ‘sizeof’ applied to a bit-field ...obviously, since it...

When are static function variables allocated?

I have a question in allocation of memory for static variables. Please look at the following snippet. #include<stdio.h> #include<conio.h> void fun(); static int a; void main() { fun(); getch(); } void fun() { static int b; } Can someone please explain me when memory will be allocated for static int b in function fun (b...

Learning OpenGL with a Strong Math Foundation?

I am looking to learn open GL, I have a strong foundation of the maths behind graphics. What is the best route to take in learning the Open GL technology i'm open to using both Windows and Mac. Thanks in advance ...

How can I get how many bytes sscanf_s read in its last operation?

I wrote up a quick memory reader class that emulates the same functions as fread and fscanf. Basically, I used memcpy and increased an internal pointer to read the data like fread, but I have a fscanf_s call. I used sscanf_s, except that doesn't tell me how many bytes it read out of the data. Is there a way to tell how many bytes ssc...

Brute-force sudoku solver: backtracking?

An implementation of a brute-force algorithm to solve Sudoku puzzles fails if a cell is discovered in which placing any of the digits 1-9 would be an illegal move. The implementation is written in C, with the board represented by a 9x9 array. The solver counts down from 9 until a legal number's reached, and if none can be reached, it ou...

Dynamically loading two libpython versions

I have a program which embeds both python2 and python3 interpreters. The libpython shared libraries are dlopen()ed by the respective commands which provide access to the interpreters and each interpreter maintains its own state. This all works just fine if the user only uses pure python modules or builtins. Trying to load a C extensio...

How can I call (not define) a function with a variable number of arguments in C?

Is there any way to make this code shorter? long call_f(int argc, long *argv) { switch (argc) { case 0: return f(); break; case 1: return f(argv[0]); break; case 2: return f(argv[0], argv[1]); break; case 3: return f(argv[0], argv[1], argv[2]); break; case 4: re...

C variable variables

in PHP, I have something like function doStuff($in, $value) { $var = "V_" . $in; $$var = $value; } Is there a way to do something similar in C? Basically I'm trying to figure out how to make a sort of library to make working with IO pins on an AVR easier. So for example, there would be a function to set a particular pin ...

What's the difference between hard and soft floating point numbers?

When I compile C code with my cross toolchain, the linker prints pages of warnings saying that my executable uses hard floats but my libc uses soft floats. What's the difference? ...

Socket client/server input/output polling vs. read/write in linux

Basically I set up a test to see which method is the fastest way to get data from another computer my network for a server with only a few clients(10 at max, 1 at min). I tried two methods, both were done in a thread/per client fashion, and looped the read 10000 times. I timed the loop from the creation of the threads to the joining of ...

Side effects of exit() without exiting?

If my application runs out of memory, I would like to re-run it with changed parameters. I have various malloc-s/new-s in various parts of the application, the sizes of which are not known in advance. I see two options: Track all memory allocations and write a restarting procedure which deallocates all before re-running with changed pa...