c

Why not port Linux kernel to Common Lisp?

Conventional wisdom states that OS kernels must be written in C in order to achieve the necessary levels of performance. This has been the justification for not using more expressive high level languages. However, for a few years now implementations of Common Lisp such as SBCL have proven to be just as performant as C. What then are t...

On the Design of zero-copy Memory allocators used in high volume fast-path code.

Disclaimer: please do not bother reading this long post unless you are an embedded programmer, or a kernel developer, or a high performance system software programmer. It is about memory allocators and might not be of any interest to you. I am building a library for high-volume high-performance same machine IPC, using OS specific pipes...

summary: malloc.c:3074 - Why does this code causes the error

The attached below C code when run gives the error summary: malloc.c:3074: sYSMALLOc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+...

build python program with extensions using py2exe

I'm having a hard time finding py2exe recipes, especially for cases that require c extensions. The following recipe works fine without the "ext_modules" part. With it I get "NameError: name 'Extension' is not defined. from distutils.core import setup import py2exe import matplotlib import os s = os.popen('svnversion') version = s.r...

How to return string from a char function

I want the function getCategory() to return "invalid" , instead of printing the word "invalid" (i.e instead of using printf ) when input to the function is invalid (i.e.when either height or weight are lower then zero). please help: #include<stdio.h> #include<conio.h> char getCategory(float height,float weight) { char invalid = '\0'; ...

biggest integer that can be stored in a double

What is the biggest "no-floating" integer that can be stored in a double C type (IEEE) without loosing precision ? ...

C style printf/scanf

I've seen, here and elsewhere, many questions that, to get input data, use something like this: ... printf("What's your name? "); scanf("%s",name); ... This is very reminiscent of the old BASIC days (INPUT for those who remember it). The majority of those questions, if not all, are from people just learning C and are homeworks or...

[C] Why return a negative errno? (e.g. return -EIO)

Another simple example: if (wpa_s->mlme.ssid_len == 0) return -EINVAL; Why the unary minus? Is this (usually) done for functions that return >0 on success and <(=)0 on failure, or is there some other reason? ...

lseek function problem in a copy file program!

Hi ppl Got to use lseek function in this program below... Program is simply copying file (that already exist). I wanned to copy the existing file with the chars from the end of file for example: Sorce_File.txt contains:"1 2 3" after copy Target_File.txt contains:"3 2 1" I'm pretty sure it's simple problem but couldn't find out since 2...

JNI / C library: passing byte ptr

I have an unsigned char* in my C library, and Im calling a JNI exported function that needs to set a java object with this data... preferably in a byte[]. But this function will be called very often, and it's quite a lot of data to be copied.. Is it possible to use a ByteBuffer and assign the pointer of that bytebuffer to my unsigned ch...

Why do C enumeration constants need a name?

Why do C enumeration constants need a name? Because this: #include <stdio.h> enum {NO, YES}; int main(void) { printf("%d\n", YES); } works just the same as this: #include <stdio.h> enum boolean {NO, YES}; int main(void) { printf("%d\n", YES); } ...

Best practices: Where should function comments go in C/C++ code?

So... I understand this might be subjective, but I'd like some opinions on what the best practice for this is. Say I have the following header and .cpp file: header: // foo.h class foo { public: int bar(int in); }; cpp: // foo.cpp int foo::bar(int in) { // some algorithm here which modifies in and returns the modified val...

Checking an array of data for similar elements in C

Hi, I created an "address" structure. Each address (xx.yy.zz.mm) consists of an xx, yy, zz and mm element, all of which are ints. Each address also has a "name" element associated with it. I have an array of up to 100 addresses called "network". Here is an example of some elements in network: 186.88.1.21 Tyler 186.88.9.11 Bob 101.21.0...

open process as different user

hi all I want to get the privileges of a selected user on a local machine. I know how to get them from the current user, so my problem is how to open a process as as a different user. I'm currently looking for more info about CreateProcessAsUser() thanks ...

Should I use msgsnd or mq_send?

I'm learning Unix IPC, and my book only talks about the msg* family of functions. However while browsing the man pages I learned about the mq_ equivalents. http://techpubs.sgi.com/library/tpl/cgi-bin/getdoc.cgi/0650/bks/SGI%5FDeveloper/books/T%5FIRIX%5FProg/sgi%5Fhtml/ch06.html describes some differences between the two, but I'm not sure...

Lost in Multiple Fork(), Pipe() and Select()

Hello, Hope I can find some help here cause I'm starting to give up. Heads up as this is an homework assignment, hence why it might be stupid. Context: Have to program something which will be shell executed as such: logn [--tick n] cmd [args] [, cmd [args]]... Basically, it's a program that multiple programs simultanously. Constraint...

Why should #ifdef be avoided in .c files?

A programmer I respect said that in C code, #if and #ifdef should be avoided at all costs, except possibly in header files. Why would it be considered bad programming practice to use #ifdef in a .c file? ...

Is it possible to tell the branch predictor how likely it is to follow the branch?

Just to make it clear, I'm not going for any sort of portability here, so any solutions that will tie me to a certain box is fine. Basically, I have an if statement that will 99% of the time evaluate to true, and am trying to eke out every last clock of performance, can I issue some sort of compiler command (using GCC 4.1.2 and the x86 ...

C : Store and index a HUGH amount of info! School Project

Hi, i need to do a school project in C (I'm really don't know c++ as well). I need a data struct to index each word of about 34k documents, its a lot of words, and need to do some ranking about the words, i already did this project about 2 years ago (i'm pause in the school and back this year) and a i use a hash table of binary tree, bu...

Determining output (printing) of float with %f in C/C++

I have gone through earlier discussions on floating point numbers in SO but that didn't clarified my problem,I knew this floating point issues may be common in every forum but my question in not concerned about Floating point arithmetic or Comparison.I am rather inquisitive about its representation and output with %f. The question is ...