c

Why are there digraphs in C and C++?

I learned today that there are digraphs in C99 and C++. The following is a valid program: %:include <stdio.h> %:ifndef BUFSIZE %:define BUFSIZE 512 %:endif void copy(char d<::>, const char s<::>, int len) <% while (len-- >= 0) <% d<:len:> = s<:len:>; %> %> My question is: why do they exist? ...

How do you ensure that you as programmer have written quality C code?

hi all, I m looking to write some quality C code. Can someone point me to some articles , websites..whatever I need something with examples. I have already seen and read K&R C book. But times have changed, some one must have more to say on quality C Code. and another important thing is How do you ensure that you as programmer have wri...

Why isn't OCaml more popular?

I've always heard that C is the language of choice to use for embedded systems, or anything that needs to run at maximum speed. I never developed a fondness for C, mostly because I don't like pointer arithmetic and the language is barely a rung above assembler. On the other hand, ML languages are functional, garbage collected languages...

Portable and simple unicode string library for C/C++?

I'm looking for a portable and easy-to-use string library for C/C++, which helps me to work with Unicode input/output. In the best case, it will store its strings in memory in UTF-8, and allow me to convert strings from ASCII to UTF-8/UTF-16 and back. I don't need much more besides that (ok, a liberal license won't hurt). I have seen th...

Minimal XML library for C++?

What XML libraries are out there, which are minimal, easy to use, come with little dependencies (ideally none), can be linked statically and come with a liberal license? So far, I've been a pretty happy user of TinyXML, but I'm curious what alternatives I have missed so far. ...

Is there is a software caching API out there?

Hi all, I'm looking for an API or an application that can cache data from a file or database. My idea is that I have an application that reads a database, but the access to database is sequential and it is on a disk. What I basically want to do is get the data from cache first and then if it doesn't exist in cache, then hit the databas...

Converting to Multi-Threaded Socket Application

As I am currently doing this project in only C, I've up untill this point only used my webserver as a single threaded application. However, I dont want that anymore! So I have the following code that handles my Work. void BeginListen() { CreateSocket(); BindSocket(); ListenOnSocket(); while ( 1 ) ...

Logical error with functions in C

Hi guys I'm a junior student in IT. I am facing a problem with the output of the program. The idea of the program is that I should use functions to read an array of 10 elements, then get the average of the elements, then get the the max and min. I've got the max and min right but the average is showing weird stuff. Please check the cod...

How to convert struct to char array in C

I'm trying to convert a struct to a char array to send over the network. However, I get some weird output from the char array when I do. #include <stdio.h> struct x { int x; } __attribute__((packed)); int main() { struct x a; a.x=127; char *b = (char *)&a; int i; for (i=0; i<4; i++) printf("%02x ", b[i]); ...

Segfault from adding a variable

I'm admittedly a straight-C newbie, but this has got me stumped. I'm working on a linked list implementation for practice, and I'm getting a segfault by simply adding a variable to the split_node function: #include <stdio.h> #include <string.h> #include <stdlib.h> struct Node { struct Node *child; char *content; }; void print_list(s...

Why are C character literals ints instead of chars?

In C++, sizeof('a') == sizeof(char) == 1. This makes intuitive sense, since 'a' is a character literal, and sizeof(char) is defined to be 1 by the standard. But in C, sizeof('a') == sizeof(int). That is, it appears that C character literals are actually integers. Does anyone know why? I can find plenty of mentions of this C quirk but no ...

C library vs WinApi

Hi, Many of the standard c library (fwrite, memset, malloc) functions have direct equivalents in the windows API (WriteFile, FillMemory/ ZeroMemory, GlobalAlloc). Apart from portability issues, what should be used, the CLIB or windows API functions? Will the C functions call the winapi functions or is it the other way around? thanks...

ungetc equivalent of c#

Is there any function in c# equivalent to C's stdio function ungetc() ? ...

Are prototypes required for all functions in C89, C90 or C99?

To be truly standards-compliant, must all functions in C (except for main) have a prototype, even if they are only used after their definition in the same translation unit? ...

Global Variable identification in C code base

I have a C code base and need to programmatically identify all of the global variables used. I think that gcc can be made to produce a memory map file but don't know how and this might let me see which variables are global? Any help would be appreciated. Cheers ...

Get info for Common Log Format from socket in C

I want to create a log file for my webserver written in C under UNIX. The logfile should be formatted according to Common Log Format, but I don't know how to get the ident and authuser from the connecting socket. Is there a simple way to get these from the socket? ...

What type of programs are best written in C

Joel and company expound on the virtues of learning C and how the best way to learn a language is to actually write programs using that use it. To that effect, which types of applications are most suitable to the C programming language? Edit: I am looking for what C is good at. This likely does not coincide with the best way of learni...

Are constant C expressions evaluated at compile time or at runtime?

If I write a #define that performs an operation using other preprocessor constants, is the final value computed each time the macro appears at runtime? Does this depend on optimizations in the compiler, or is it covered under a standard? Example: #define EXTERNAL_CLOCK_FREQUENCY 32768 #define TIMER_1_S EXTERNAL_CLO...

What is the best way to plan and organize development of an application in C?

I've only had to code in C a few times, and it seems like every time I do, it becomes some unmanageable beast. I've done most of my programming in C# and .Net so I am very accustomed to the class style architecture, but I can't seem to grasp organization in C applications. Should I put functions that are related in a certain file, put f...

How to get data out of network packet data in Java

In C if you have a certain type of packet, what you generally do is define some struct and cast the char * into a pointer to the struct. After this you have direct programmatic access to all data fields in the network packet. Like so : struct rdp_header { int version; char serverId[20]; }; When you get a network packet you can do ...