c

Measure size and way-order of L1 and L2 caches

How can I programmatically measure (not query the OS) the size and order of associativity of L1 and L2 caches (data caches)? Assumptions about system: It has L1 and L2 cache (may be L3 too, may be cache sharing), It may have a hardware prefetch unit (just like P4+), It has a stable clocksource (tickcounter or good HPET for gettimeofda...

C/C++ enums: Detect when multiple items map to same value

Is there a compile-time way to detect / prevent duplicate values within a C/C++ enumeration? The catch is that there are multiple items which are initialized to explicit values. Background: I've inherited some C code such as the following: #define BASE1_VAL (5) #define BASE2_VAL (7) typedef enum { MsgFoo1A = BASE1_VAL, ...

Please help with passing multidimensional arrays

Hi, I'm writing a simple test program to pass multidimensional arrays. I've been struggling to get the signature of the callee function. The code I have: void p(int (*s)[100], int n) { ... } ... { int s1[10][100], s2[10][1000]; p(s1, 100); } This code appears to work, but is not what I intended. I want the function p to be obl...

How do you capture a group with regex?

Hi, I'm trying to extract a string from another using regex. I'm using the POSIX regex functions (regcomp, regexec ...), and I fail at capturing a group ... For instance, let the pattern be something as simple as "MAIL FROM:<(.*)>" (with REG_EXTENDED cflags) I want to capture everything between '<' and '>' My problem is that regmatch...

C Language: Why I cannot transfer file from server to client?

I want to ask, why I cannot transfer file from server to client? When I start to send the file from server, the client side program has a problem. So, I spend some times to check the code, but I still cannot find out the problem Can anyone point out the problem for me? ps. Thanks for the administarator fix the code first. ps2. I als...

cURL - put output into variable?

Hi, I'm currently using this C code: CURL *curl; CURLcode res; curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://my-domain.org/"); res = curl_easy_perform(curl); curl_easy_cleanup(curl); } It prints the output on the console. How can I get the same output, but read it into, say, a string? ...

Number of elements in static array and dynamic array

What is the quickest way to find the number of elements in a static array and dynamic array? ...

template style matrix implementation in c

From time to time I use the following code for generating a matrix style datastructure typedef double myType; typedef struct matrix_t{ |Compilation started at Mon Apr 5 02:24:15 myType **matrix; | size_t x;...

Bitwise setting in C++

enum AccessSource { AccessSourceNull = 0x00000001, AccessSourceSec = 0x00000002, AccessSourceIpo = 0x00000004, AccessSourceSSA = 0x00000008, AccessSourceUpgrade = 0x00000010, AccessSourceDelta = 0x00000020, AccessSourcePhoneM = 0x00000040, ...

From where does the uboot get the information about flash, RTC, RAM in uboot/kernal development

From where does the uboot get the information about flash, RTC, RAM in uboot/kernal development ...

semaphores.h and threads.h in c

Hallo i need to install and libs for c.I am using a linux ubuntu o/s.Does anybody knows how i can install them? ...

Pointer Arithmetic & Signed / Unsigned Conversions!

Incase of pointer arithmetic, are the integers automatically converted to their signed variants? If yes, why? Suppose I do int *pointer; int *pointerdiff; unsigned int uiVal = -1; pointerdiff = pointer + uiVal // Pointer will contain valid address here. where pointer is a pointer to int and uiVal is initialized to -1, then I find...

C precision of double: compiler dependent?

Hi,on my 32-bit machine (with an Intel T7700 duo core), I have 15 precision digits for both double and long double types for the C language. I compared the parameters LDBL_DIG for long double and DBL_DIG for double and they are both 15. I got these answers using MVS2008. I was wondering if these results can be compiler dependent or do th...

Good books on numerical computation with C

Hi, I've read the post "What is the best book on numerical methods?" and I wish to ask more or less the same question but in relation to C programming. Most of the time, C programming books on numerical methods are just another version of the author's previous Fortran book on the same subject. I've seen Applied numerical methods in C by ...

How to tell where I am in an array with pointer arithmetic?

In C, I have declared a memory area like this: int cells = 512; int* memory = (int*) malloc ((sizeof (int)) * cells); And I place myself more or less in the middle int* current_cell = memory + ((cells / 2) * sizeof (int)); My question is, while I increment *current_cell, how do I know if I reached the end of the allocated memory ar...

Can somebody tell steps to use OpenAMQ C lib to connect to rabbitMQ server.

I am trying to use RabbitMQ in my C/C++ app, so far I have realized that using OpenAMQ's C Client is the only option, but OpenAMQ is AMQP 0-9 something and RabbitMQ server is 0-8. I have read somewhere that people were successful to do minor changes to RabbitMQ to make it work with OpenAMQ C lib.. can somebody experienced with this throw...

Determining whether compiling on Windows or other system

Hi, Im currently developing a cross-platform C application. Is there any compiler macro which is defined only during compilation on Windows, so I can #ifdef some Windows specific #includes? Typical example is selecting between WinSock and Berkeley sockets headers: #ifdef _WINDOWS #include <winsock.h> #else #include <sys/sock...

Signedness of enum in C/C99/C++/C++x/GNU C/GNU C99

Hello Is enum type signed or unsigned? Is the Signedness of enums differ in C/C99/ANSI C/C++/C++x/GNU C/ GNU C99? Thanks ...

-I dir vs. -isystem dir

If I want to include directories to be searched for header files, which is the preferred way and why? ...

Lifetime of a const string literal returned by a function

Consider this code: const char* someFun() { // ... some stuff return "Some text!!" } int main() { { // Block: A const char* retStr = someFun(); // use retStr } } My question is in the function sumFun() where is "some Text!!", stored (i think may be in some static area in ROM) and what will be its scope? Wi...