c

Invoking GCC as "cc" versus "gcc"

I am aware that on most GNU/Linux systems, GCC can be invoked by the name "cc" from the command line (as opposed to "gcc"). What I am wondering is if there is any difference in GCC's behavior when it is invoked one way versus the other. For example, I know that invoking GCC through the name "g++" instead of "gcc" causes GCC to behave di...

What's the correct way to use printf to print a size_t?

Size_t is defined as an unsigned integer, but the size of it depends on whether you're on a 32 or 64-bit machine. What's the correct and portable way to print out a size_t? ...

SIC Assembler I/O question

I've coded a SIC assembler and everything seems to be working fine except for the I/O aspect of it. I've loaded the object code into memory (converted char format into machine representation), but when I call SICRun(); to execute the code, I get an error stating "devf1 cannot be found". I know this is related to the input/output devi...

Function prototype declared inside main - best practice?

Is this a good style to have the function prototype declared inside of the main function? I was looking at a C tutorial, I think is quite out of date. However, they declare the function prototype inside of main. I normally declare outside before main. #include "stdio.h" int main() { char myname[30]; int theage; int getage(); printf("...

Which libraries should a C or C++ newbie know?

I recommended my friend the libraries in the book Numerical Recipes. However, it seems that they are too challenging for him. I am not sure which libraries are the best for a newbie in C/C++. Which libraries should a C or C++ newbie know? ...

Example usage where Lua fits much better than C/C++

I'm currently embedding Lua and using it as a glorified intelligent config file. However, I think I'm missing something since people rave about the uses of Lua. For example, I can easily explain why you might use shell scripting instead of C by showing this example (admittedly , boost regexp is overkill): #include <dirent.h> #include ...

Is it reasonable to integrate python with c for performance?

Hi, I like to use python for almost everything and always had clear in my mind that if for some reason I was to find a bottleneck in my python code(due to python's limitations), I could always use a C script integrated to my code. But, as I started to read a guide on how to integrate python. In the article the author says: There are se...

In C/C++ why does the do while(expression); need a semi colon?

My guess is it just made parsing easier, but I can't see exactly why. So what does this have ... do { some stuff } while(test); more stuff that's better than ... do { some stuff } while(test) more stuff ...

Help me to port this NetHack function to Python please!

Hi, I am trying to write a Python function which returns the same moon phase value as in the game NetHack. This is found in hacklib.c. I have tried to simply copy the corresponding function from the NetHack code but I don't believe I am getting the correct results. The function which I have written is phase_of_the_moon(). The functio...

Recursively freeing C structs

I have a struct that only contains pointers to memory that I've allocated. Is there a way to recursively free each element that is a pointer rather than calling free on each one? For example, let's say I have this layout: typedef struct { ... } vertex; typedef struct { ... } normal; typedef struct { ... } texture_coord; typedef struct...

How I get child threads wait on a condition and all waked up by one call from parent thread?

Child threads sleeps to wait condition, and the parent thread can call some routine to wake up all child threads to run? ...

TTCN to C conversion

is there a open source TTCN tool which can convert TTCN script to C ...

How do you split source code in C into separate files?

I'm trying to read other peoples code but most code is broken up into separate files. I haven't learned how to do that yet. How do you split up code into separate files? And how do you find the right source code file for a function? ...

assigning character to char pointer

With c-style strings, how do you assign a char to a memory address that a character pointer points to? For example, in the example below, I want to change num to "123456", so I tried to set p to the digit where '0' is located and I try to overwrite it with '4'. Thanks. #include <stdio.h> #include <stdlib.h> int main() { char* num ...

Segmentation fault - char pointer

In the code below, the line: *end = *front; gives a segmentation fault. I asked a similar question here but I'm not sure if this is because I have two copies of num. Please explain why it's seg-faulting. Thank you. #include <stdio.h> #include <stdlib.h> #include <string.h> char* getPalin(char* num); int main() { char* num = (c...

Real-life C application to show at introductory course

I am holding a course on the C programming language, and I want to show the students some real-life useful applications of C, to catch their interest. Usually all they see are boring programs, with no practical utility, so I am wondering what sort of useful applications can be presented, maybe something that they can use on their own (ho...

gcc optimization flags for Xeon?

Hi, I'd want your input which gcc compiler flags to use when optimizing for Xeons? There's no 'xeon' in mtune or march so which is the closest match? ...

How to simulate exceptions in C with goto?

I'm writing a concurrent transaction library in C and found the following problem. Let's consider a sample transaction member pseudo-code, where the "transaction" represents a communication channel with the transaction master: transaction = trans_join(); do_some_ops(); /* receive the data from the master */ trans_rcv(transaction, data...

What exactly is meant by the range of any data type? e.g. range of integer?

hi .....plz clarify what exactly does range define? ...

How can I link *.c files in Visual Studio 2005 using make file option?

What is the option for linking the source files in Visual Studio in makefile? I have given it as 'link', but that doesn't work. The option for compilation is 'cl'. This is working well. I want to know the link option. ...