c

PInvoke returns C type with union

How would I P/Invoke a C function which returns a union'ed struct? ...

Sequence points and partial order

A few days back there was a discussion here about whether the expression i = ++i + 1 invokes UB (Undefined Behavior) or not. Finally the conclusion was made that it invokes UB as the value of 'i' is changing more than once between two sequence points. I was involved in a discussion with Johannes Schaub in that same thread. Accor...

I am writing a function to do "while" , but why error?

I am writing a function to do "while" to count the numbers of alphabetic and digits in a text file. I would like to seperate it to 2 functions of 2 "while". But it error after I create the first function. What's wrong of it? #include "stdafx.h" #include "stdlib.h" #include "ctype.h" void countDig (FILE* input, char num,...

Recommended integration mechanism for bi-directional, authenticated, encrypted connection in C client/JVM server setup?

Let me first give an example. Imagine you have a single server running a JVM application. This server keeps a collection of N equations, once for each client: Client #1: 2x Client #2: 1 + y Client #3: z/4 This server includes an HTTP interface so that random visitors can type https://www.acme.com/client/3 int their browsers and see ...

How to get a brightwhite color in ncurses?

How to init a color pair with light grey background, and bright white foregraound? init_pair(number, COLOR_WHITE, COLOR_WHITE) creates a color pair with light grey foreground and backround, but I need foreground to be really white. I tried combining COLOR_WHITE with A_BLINK (through bitwise OR) but that doesn't work. Ncurses howto's/exa...

Is this C code wrong?

I know that pointers contain the addresses of variables, for example: int c = 5; int *p; p = &c; printf("%d",*p); // Outputs 5. But what if I want to send an address to a function: void function (int *p) { p++; } int c; function (&c); When function is called, the value of &c is assigned to int *p. I guess that the exact instruc...

Detecting CPU capability without assembly

I've been looking at ways to determine the CPU, and its capabilities (eg SEE,SSE2,etc). However all the ways I've found involved assembly code using the cpuid instruction. Given the differing ways of doing assembly in c/c++ between compilers and even targets (no inline assembly for 64bit targets under VC), id rather avoid that. Is ther...

linking assembly and c problem

Trying to understand how to link a function that is defined in a struct, the function is in the assembly code, and am trying to call it from c. I think am missing a step cause when I call the function, I get an unresolved external symbol... ;Assembly.asm .686p .mmx .xmm .model flat include Definitions.inc .code ?Initialize@Foo@@SIXPA...

[C Program] Probems about "isspace"

Difficulties appear in my homework again. I am writing a program to count the number of whitespace characters in a text file. I use "isspace" to count it. The content in the text file is "1 1 1", but the counter still 0, what's wrong of the codes? #include "stdafx.h" #include "ctype.h" int _tmain(int argc, _TCHAR* argv[]) { FILE* input...

Capture microphone audio stream in Windows using C

I'm looking to build a Morse decoder (and eventually a coder) in C. I'd like to use the audio port as input, and sample the incoming voltage on the port. How do I go about reading the voltage on a microphone audio port in Windows using C? ...

Linking two object files with a common symbol

If i have two object files both defining a symbol (function) "foobar". Is it possible to tell the linker to obey the obj file order i give in the command line call and always take the symbol from first file and never the later one? AFAIK the "weak" pragma works only on shared libraries but not on object files. Please answer for all th...

detecting loops in symbolic links (c programming)

I'm looking to detect loops in symbolic links in a C program: $ ln -s self self $ ln -s a b $ ln -s b a Here's what I've got so far: #include <sys/stat.h> #include <stdio.h> #include <string.h> #include <unistd.h> #include <errno.h> int main(int argc, char *argv[]) { struct stat buffer; int status; if (argc != 2) { ...

Problem with scanf in Eclipse / MiniGW

I'm trying to run the following code in eclipse but the console remains blank until i stop the program at which point the output "Enter next value (<=0 to quit)2130567168 minutes is 35509452 hours, 48 minutes." is repeated over and over. It seems that scanf is putting some default value in for some reason... can't figure out why. I'm no...

getopt implicit declaration in Solaris?

In Solaris, gcc gives me implicit declaration of function `getopt' when compiling #include <unistd.h> #include <stdlib.h> int main(int argc, char *argv[]) { getopt(1,argv,""); return 0; } The man page for getopt says something about including unistd.h or stdio.h, however even though I'm inluding both I still get this w...

How to determine if memory is aligned? ( *testing* for alignment, not aligning )

Hi there, I am new to optimizing code with SSE/SSE2 instructions and until now I have not gotten very far. To my knowledge a common SSE-optimized function would look like this: void sse_func(const float* const ptr, int len){ if( ptr is aligned ) { for( ... ){ // unroll loop by 4 or 2 elements } ...

turning off DEBUG macros for a specific function (NDEBUG)

Hi, I am using the following macro for printing debug information that I found on the web. It works great. However, I would like to turn-off debug printing for function A when debugging function B, which calls function A. I tried #define NDEBUG function A #undef NDEBUG but haven't managed to suppress printing in function A. Any hel...

Problems writing the memset function

Hi, I am writing the memset function and my code is below, I am having a problem void* memsetFun(void* pointer, int c, int size) { if ( pointer != NULL && size > 0 ) { unsigned char* pChar = pointer; int i = 0; for ( i = 0; i < size; ++i) { unsigned char temp = (unsigned char) c; *pChar++ = temp; // ...

forking multiple processes and making the parent wait for all of them (in C)

I'm creating various processes (3 to be precise) and making them do different things. So far so good. I'm trying to wait in the parent until all children are completed. I've played around with many options (such as the one listed below) but either the parent waits but I have to press enter to return to the shell (meaning that some child...

System call in unix: directories and files

hi I'm trying to understand system calls: directories and files on unix, .. I found this website where they explain some calls with their own examples, but do not understand these code snippets .. void state (char *file) { struct stat buf; struct passwd *pw; struct group *gr; int i; if (stat(file, &buf)...

sizeof array of structs in C?

In C I have an array of structs defined like: struct D { char *a; char *b; char *c; }; static struct D a[] = { { "1a", "1b", "1c" }, { "2a", "2b", "2c" } }; I would like to determine the number of elements in the array, but sizeof(a) returns an incorrect resu...