c

Errors When Using Bison

Now I'm getting other things. When I do a bison -d calc.y I'm getting many source codes in the console (with many m4_define), but it doesn't generate any file. Now my code is like this: %{ #define YYSTYPE double #include <math.h> %} %token NUM %% input: /* empty */ | input line ; line: '\n' | exp '\n' { printf...

Is possible to use nanosleep in a infinite loop with select()?

Hi, I have a C program that do recv/send operations from/to socket using a for(;;) loop and a select() to monitor the file descriptor. I need also this program to send a packet every 80msec to a packet, how can I implement this? Maybe I can use a fork() and the child process simply write an ack in one of the file descriptor monitored b...

How to eliminate flicker on a sizable dialog?

I've got a sizable dialog with one child window - a list control. When the dialog is re-sized, I re-size the list control appropriately; it is basically anchored to all 4 edges of the dialog. The problem is that during sizing there is noticeable flicker around the edges of the list control, especially when the scroll bars are present. ...

Local Chat server in C using IPC

Hi Guys I need to write a chat server in C. It only needs to use IPC. Could you help me on how to proceed on this. A skeleton code will help me a lot. ...

What exactly does "ar" utility do?

I don't really understand what ar utility does on Unix systems. I know it can be somehow used for creating c libraries, but all that man page tells me is that it is used to make archives from files, which sounds similar to, for example, tar.... ...

How to capture unbuffered output from stdout without modifying the program?

I'm writing a utility for running programs, and I need to capture unbuffered stdout and stderr from the programs. I need to: Capture stdout and stderr to separate files. Output needs to not be buffered (or be line buffered). Without modifying the source of the program being run. The problem is, when piping output to a file, the stdou...

How to declare C array of strings

I'm working on a simple lex program for class, and in it I'm creating a very rudimentary symbol table, just an array of strings with a linear scan for search. I've declared it as: char* identifiers[100]; And I'm using it like so: found = false; for (i = 0; i < seen_identifiers; i++) { if (!strcmp(identifiers[i], yytext)) { ...

Using strftime in C, how can I format time exactly like a Unix timestamp?

Here's the sort of time formatting I'm after: 2009-10-08 04:31:33.918700000 -0500 I'm currently using this: strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S %Z", ts); Which gives: 2009-10-11 13:42:57 CDT Which is close, but not exact. I can't seem to find anything on displaying '-0500' at the end. Plus I'm getting the seconds as an int. ...

c alternative to signal() + alarm()

I'm building some FastCGI apps and it sort of bugs me that lighttpd doesn't kill them off after they've been idle, so I'm trying to have them close on their own. I tried using signal(SIGALRM, close); alarm(300); and having the close function execute exit(0), and that works almost well. The problem is the close function is being call...

Calculating Highest Power of 2 That Evenly Divides a Number in C

I need to write some logic to determine, given an even number, the highest power of two that evenly divides it. What is the maximum value of 2^n where Input % 2^n == 0? IE: Input -> Output 4 (0100) -> 4 8 (1000) -> 8 12 (1100) -> 4 14 (1110) -> 2 24 (11000) -> 8 etc.... It looks like there be some bitwise logic that may ...

strncmp C Exercise

I'm trying to do exercise 5-4 in the K&R C book. I have written the methods for strncpy and strncat, but I'm having some trouble understanding exactly what to return for the strncmp part of the exercise. The definition of strncmp (from Appendix B in K&R book) is: compare at most n characters of string s to string t; return <0 if s...

Why are most of the biggest open source projects in C?

Hi, I'm having a debate with a friend and we're wondering why so many open source projects have decided to go with C instead of C++. Projects such as Apache, GTK, Gnome and more opted for C, but why not C++ since it's almost the same? We're precisely looking for the reasons that would have led those projects (not only those I've listed...

Emacs comment-region in C mode

In GNU Emacs, is there a good way to change the comment-region command in C mode from /* This is a comment which extends */ /* over more than one line in C. */ to /* This is a comment which extends over more than one line in C. */ ? I have tried (setq comment-multi-line t) but this does not help. There is a section on multi-...

How to allow a user to edit data in a separate app from the terminal?

I am writing a terminal-based application, but I want the user to be able to edit certain text data in a separate editor. For example, if the user chooses to edit the list of current usernames, the list should open as a text file in the user's favorite editor (vim, gedit, etc.). This will probably be an environment variable such as $MY...

Launch OpenGL app straight from a windowless Linux Terminal

How exactly would one go about getting an OpenGL app to run fullscreen straight from the terminal (Ubuntu Server 9.04)? I've developed an application for visual diagnostics on my server, but, I'm not totally sure the best way to get it to run in a windowless environment. Ideally, I would run my program: ./visualdiagnostics and have...

Writing an OS for Motorola 68K processor. Can I emulate it? And can I test-drive OS development?

Next term, I'll need to write a basic operating system for Motorola 68K processor as part of a course lab material. Is there a Linux emulator of a basic hardware setup with that processor? So my partners and I can debug quicker on our computers instead of physically restarting the board and stuff. Is it possible to apply test-driven d...

Can I substitute __func__ into an identifier name in a C macro?

I'd like to write a C macro which takes this: int foo() { MY_MACRO } and expands it to this: int foo() { _macro_var_foo++; } I've found that I can't use __func__, because that doesn't actually get expanded in the macro; it's treated by the preprocessor like a variable. Is there some way to get this to work? ...

Is there a Java equivalent of frexp?

Is there a Java equivalent of the C / C++ function called frexp? If you aren't familiar, frexp is defined by Wikipedia to "break floating-point number down into mantissa and exponent." I am looking for an implementation with both speed and accuracy but I would rather have the accuracy if I could only choose one. This is the code sampl...

convert 24bit RGB to ARGB16

hi, i am reading a 24bpp bitmap , and i need to convert each pixel from RGB24 to ARGB16. i am using this : #define ARGB16(a, r, g, b) ( ((a) << 15) | (r)|((g)<<5)|((b)<<10)) but the output it's not what i need, can someone offer some help ? thank you. ...

What is the good approach to build a new compiler ?

I have an experience about the compiler phrases and I interested in Programming Languages & Compilers field and I hope somebody gives me some explanation about what is the good approach to write a new compiler from scratch for a new programming language ? (I mean STEPS). ...