c

Using SO_REUSEADDR - What happens to previously open socket?

Hi Everyone, In network programming in unix, I have always set the SO_REUSEADDR option on the socket being used by server to listen to connections on. This basically says that another socket can be opened on the same port on the machine. This is useful when recovering from a crash and the socket was not properly closed - the app can be ...

Understanding evaluation of expressions containing '++' and '->' operators in C.

Consider this example: struct { int num; } s, *ps; s.num = 0; ps = &s; ++ps->num; printf("%d", s.num); /* Prints 1 */ It prints 1. So I understand that it is because according to operators precedence, -> is higher than ++, so the value ps->num (which is 0) is firstly fetched and then the ++ operator operates on it, so it incre...

Bit packing in C

I'm trying to convert an RGB image to an ARGB image, basically just adding 255 in for the alpha channel. I was wondering if there is any pack method to do this without iteration? So to iterate over my RGB data and append the 255 to each pixel. ...

How to know a thread memory usage?

Hello, is it possible to know how much memory is being used by a given phtread thread? I am interested by a VmRSS like information. ...

Calculate broadcast address from ip and subnet mask

Hi I want to calculate the broadcast address for e.g -IP 192.168.3.1 -Subnet 255.255.255.0 =192.168.3.255 in C. I know the way (doing fancy bitwise OR's between the inversed IP and Subnet), but my problem is I come from the green fields of MacOSX Cocoa programing. I looked into the source of ipcal, but wasn't able to integrate it into...

How to dynamically create and read structs in C?

Hello! How can I do something like that (just an example): any_struct *my_struct = create_struct(); add_struct_member(my_struct, "a", int_member); add_struct_member(my_struct, "b", float_member); So that I could load and use a struct instance "from the outside" (at the address addressOfMyStruct) with the given structure here? any_st...

How to name a thread in Linux?

I have a multithreaded Linux application written in C/C++. I have chosen names for my threads. To aid debugging, I would like these names to be visible in GDB, "top", etc. Is this possible, and if so how? (There are plenty of reasons to know the thread name. Right now I want to know which thread is taking up 50% CPU (as reported by ...

How do I use C++ in flex and bison?

I have a project for school where we need to use flex and bison. I want to use C++ so that I have access to STL and my own classes that I wrote. We were provided with the following Makefile: CC = gcc CFLAGS = -g OBJs = parse.tab.o symtab.o attr.o lex.yy.o default: parser parser: ${OBJs} ${CC} ${CFLAGS} ${OBJs} -o parser -lfl ...

Identifying the types of all variables in a C project

I am trying to write a program to check that some C source code conforms to a variable naming convention. In order to do this, I need to analyse the source code and identify the type of all the local and global variables. The end result will almost certainly be a python program, but the tool to analyse the code could either be a python...

Unified authentication library

The idea of unified authentication behind a single API like PAM is very attractive to me. However, PAM seems to be more oriented toward shell authentication and offer a rather limited set of features from its API and require system-wide configuration from a file. I'm looking for something like this for a CGI (C language) web interface t...

client-server programme

We have made simple client.c and server.c programme in an UNIX environment. We are using it transfer a simple text file by first opening it, then reading it and sending using open, read, and send system calls; on client side I am receiving it, and writing it by creating a file on server machine. The transfer is taking place quite smoot...

Format specifiers for fixed-width integers?

What are the format specifiers to use for printf when dealing with types such as int32_t, uint16_t and int8_t, etc.? Using %d, %i, etc. will not result in a portable program. Is using the PRIxx macros the best approach? ...

What is the best/fastest way to learn GLADE with C?

I just downloaded and installed GLADE. What are some good tutorials for the C language? ...

excellent examples of real c/c++ code? Suggestions needed

I'd like to study some good c/c++ code. The code should: be good in style and structure, presenting best practices be a real life program (not an example or toy) not too big so it doesn't takes ages to analyse it Windows and/or Unix I know there are 1000s of open source projects out there. But I'd like to hear your suggestions. ...

C or C++ compiler for the Tandy 1000 PC SX?

I have my dad's old PC from the 1980's. It's a Tandy 1000 PC SX: This computer doesn't have a modem, but I have another PC that has Windows XP on it and it also has a 5 3/4 inch floppy drive. So where can I find a C/C++ compiler for this old PC? If you don't help me I'll be forced to program in GW-BASIC. ...

How to get GTK syntax highlighting in GEdit?

I just started using GTK to develop my GUI applications. I'm using GEdit as my text-editor, so how can I get the following to be included in the syntax highlighting: GtkWidget *window; GtkWidget *button GtkWidget *box1; gtk_init(&argc, &argv); as if it were like this: int x = 3; ...

What is the function to replace string in C?

Given a (char *) string, I want to find all occurrence of a substring and replace it with an alternate string. I do not see any simple function that achieves this in <string.h> ...

Should I use char** argv or char* argv[] in C?

I'm just learning C and was wondering which one of these I should use in my main method. Is there any difference? Edit: So which one is more common to use? ...

C code for solar azimuth angle given date, time, lat, and long

I seem to have asked my question wrong so here goes again I'll try to be more to the point. Is the top answer on this page http://stackoverflow.com/questions/257717/position-of-the-sun-given-time-of-day-and-lat-long the solution to the question asked or is more needed? Thanks ...

Why are many VMs written in C when they look like they have C++ features?

I noticed some not so old VM languages like Lua, NekoVM, and Potion written in C. It looked like they were reimplementing many C++ features. Is there a benefit to writing them in C rather than C++? ...