I want to write a macro in C that accepts any number of parameters, not a specific number
e.g.
#define macro( X ) something_complicated( whatever( X ) )
where X is any number of parameters
I need this because whatever is overloaded and can be called with 2 or 4 parameters.
I tried defining the macro twice, but the second definiti...
I've heard that i++ isn't a thread-safe statement since in assembly it reduces down to storing the original value as a temp somewhere, incrementing it, and then replacing it, which could be interrupted by a context switch.
However, I'm wondering about ++i. As far as I can tell, this would reduce to a single assembly instruction, such as...
Hi,
while(((long)(1000*ratio*((long)clock()-(long)t0))%100)/1000)<Data_Read_Rate);
The above line is generating the following error:
"Syntax Error before < token".
Why is this error coming up?
I use MINGW32 for development(GCC compiler).
Thanks...
...
Can you use shared memory to communicate between php scripts and c program in windows?
The c program runs all the time and uses memory mapped files ie:
handle1 = CreateFileMapping(
(HANDLE)0xFFFFFFFF, NULL, PAGE_READWRITE, 0, sizeof(byte)*BUFFER_SIZE, "my_foo" );
hView = (LPINT) MapViewOfFile(handle1, FILE_MAP_ALL_ACCESS, 0, 0, 0);
...
I need a program which prints the number of packets in a capture file which uses the pcap format. This number does not seem available in the pcap header (probably because it is written before the capture starts) and it does not seem there is a "footer" in the file, with this information.
So, I believe the only algorithm is to loop over ...
I have a structure that only one function must access. The function converts tokens like "k, K, kb, KB, m, M, mb, MB, ..." into an actual unit. The purpose of this is to simplify a configuration file.
So, suppose we have:
static uint32_t real_unit(const char *str)
{
struct u2type {
char key[3];
uint32_t val;
} const...
Duplicate of the following question: C function conflict
Hi,
in my current project I have to use some kind of interface lib. The function names are given by this interface, what this functions do is developers choice. As far as I can tell a project shall use this functions and when it comes to compiling you choose the lib and with it ...
I'm currently using a lot of the same subclassed objects with custom methods. It would be more convenient to create my own library which I can use for several projects.
The goal is to have my own classes being available in the same way classes like UIView, CGRect etc are, including convenient methods like CGRectMake, both with classes ...
How would one implement this data structure in C. It is a structure similar to the DAWG, that is more efficient than the trie which only compresses prefixes. The CDAWG is a data structure twice as space efficient as the DAWG.
...
Does the Cyrus SASL api not support the EXTERNAL mechanism? I'm trying to
use it as a client, but it returns SASL_NOMECH when asked.
% cat cyrus_sal_ex.c
/* cyrus_sasl_ex.c: Example of using the Cyrus SASL api */
#include <stdio.h> /* for printf() */
#include <sasl/sasl.h> /* for sasl_client_*(), SASL_*, sasl_*_t */
static char...
For embedded applications, it is often necessary to access fixed memory locations for peripheral registers. The standard way I have found to do this is something like the following:
// access register 'foo_reg', which is located at address 0x100
#define foo_reg *(int *)0x100
foo_reg = 1; // write to foo_reg
int x = foo_reg; // r...
In The Ten Commandments for C Programmers, what is your interpretation of the 9th commandment?
The 9th commandment:
Thy external identifiers shall be unique in the first six characters, though this harsh discipline be irksome and the years of its necessity stretch before thee seemingly without end, lest thou tear thy hair out and go...
main.h
extern int array[100];
main.c
#include "test.h"
int array[100] = {0};
int main(void)
{
/* do_stuff_with_array */
}
In the main.c module, the array is defined, and declared. Does the act of also having the extern statement included in the module, cause any problems?
I have always visualized the extern statement as...
I have a 2 column table in a database 1,000 rows long(All integer data).
The display will allow for the user to delete a certain range of data from the table.
What I am looking for is a creative way to display all the data so the user can get to different parts of it really fast. Maybe displaying different chunks at once, represent wit...
Given two file path strings with potentially different casing and slashes ('\' vs '/'), is there a quick way (that does not involve writing my own function) to normalize both paths to the same form, or at least to test them for equivalence?
I'm restricted to WinAPI and standard C++. All files are local.
...
I'm trying to receive some file through sockets in C. But the server sends me 64-byte packets for a 1000000 byte file for example and I get approximately 999902 bytes on the destination file.
while ((n = read(sd, buffer_in, BUFSIZE ))) // BUFSIZE = 64
{
if(n<0)
{
printf("Fail.\n");
fclose(archivo);
return ...
I've written a program which opens a bmp file and treats it as a character file and performs run length encoding on it. It produces a valid compressed encoding file, which I read again to perform the decoding.
When i'd made the application i was using Fedora and it ran perfectly fine. Now i'm running it on ubuntu and it refuses to work....
Hi.
I am about to port a Windows 32 Bit application to 64 Bit, but might decide to port the whole thing to Linux later.
The code contains sections which are dependent on the amount of memory available to the application (which depends on whether I'm creating a 32 or 64 Bit build), while the ability to compile a 32 Bit version of the co...
While studying C++ (and C) I had some particular doubts regarding the working of stack allocation, that I can't find a solution to:
Does stack allocation call malloc/free functions implicitly? If not; how does it assure there is no conflict between stack allocation and heap allocation?
If yes; does stack allocation in C++ implicitly ca...
I'm finding massive performance differences between similar code in C anc C#.
The C code is:
#include <stdio.h>
#include <time.h>
#include <math.h>
main()
{
int i;
double root;
clock_t start = clock();
for (i = 0 ; i <= 100000000; i++){
root = sqrt(i);
}
printf("Time elapsed: %f\n", ((double)clock() - sta...