c

How to force OpenMPI to use GCC instead of ICC? Is recompiling OpenMPI necessary?

I have a C-code for parallel computing written for gcc, and I want to compile it on a cluster, which apparently uses icc via mpicc. Correcting the code to be icc-friendly seems to be too time-demanding, so I wonder if I can ask OpenMPI to use gcc instead. I don't have the admin rights on that cluster, and I would actually prefer to do no...

fopen without fclose in C

Hi All, What happens if i open a file using fopen some n number of times without calling fclose on it? Any buffer overrun issues may arise? ...

Should I bring temporary variable declarations out of loops in C and C++?

Here is what I mean, suppose I have code like: for (int i = 0; i < 1000; i++) { char* ptr = something; /* ... use ptr here */ } It seems that char* ptr gets allocated every time in the loop, making it ineffective? Is it more effective to write this? char* ptr = something; for (int i = 0; i < 1000; i++) { /* ....

PInvoke a function from a DLL compiled in C

I have the following C function typedef struct ekeycore_ctx_ ekeycore_ctx; typedef struct ekeycore_enum_ ekeycore_enum; typedef struct ekeycore_device_ { char *serial; char *portname; char *node; BOOL present; BOOL used; } ekeycore_device; typedef struct ekeycore_simple_ ekeycore_simple; typedef enum { EKEYCO...

Why doesn't my output show up until the program exits?

I have a simple program from a C programming book, and it's supposed to ask for two integers and then add them together and show the sum. I'm able to enter the two numbers, but the output doesn't show up until the very end of the program. #include <stdlib.h> #include <stdio.h> /* Addition Program*/ main() { int integer1, intege...

C type casts and addition precedence

What's the precedence in the next expression? item = (char*)heap + offset; Is it (char*)(heap + offset) or ((char*)heap) + offset? ...

Find out if element is in enum

is there an easy way in C to figure out if an enumeration contains a certain element? ...

Good way to learn C/C++ for an otherwise experienced programmer?

I always liked coding and programming but I never got to learn it in a structured way. It has mostly been self study. I learned QBASIC, VB and PL/SQL while I was in school. Not very comprehensively, just enough to write some small fancy programs. Wanted to graduate in Comp science but somehow ended up majoring in something else. I did so...

How to pass -libm to MPICC? libimf.so: warning: feupdateenv is not implemented and will always fail

I am a newbie who tries to compile a program via mpicc replacing icc with gcc. I have already discovered, that I need to use the following command to compile $ OMPI_CC=gcc make However, I get the following error message (which is well-known) /opt/intel/fce/9.1.036/lib/libimf.so: warning: warning: feupdateenv is not implemented and wi...

Can I call a "function-like macro" in a header file from a CUDA __global__ function???

This is part of my header file ("aes_locl.h"): . . # define SWAP(x) (_lrotl(x, 8) & 0x00ff00ff | _lrotr(x, 8) & 0xff00ff00) # define GETU32(p) SWAP(*((u32 *)(p))) # define PUTU32(ct, st) { *((u32 *)(ct)) = SWAP((st)); } . . Now from .cu file I have declared a __ global__ function and included the header file like this : #include "...

recurrent declare in c

Hi All, typedef void (callback)(int *p1, sStruct *p2); typedef struct _sStruct { callback *funct; }sStruct; I have the following declaration, in C. How can I compile this recurrent declaration without receiving any error ? For the moment I receive: syntax error before '*' token on first line. ...

unistd.h and c99 on Linux

This simple .c file: #include <unistd.h> void test() { char string[40]; gethostname(string,40); } ... when compiled normally, works fine: $ cc -Wall -c -o tmp.o tmp.c $ ... but when compiled in C99 mode, gives a warning: $ cc -Wall -std=c99 -c -o tmp.o tmp.c tmp.c: In function `test': tmp.c:5: warning: implicit declaratio...

Invalid operands to binary

Hi, I have a method to check weather a number is even or odd: -(BOOL)numberIsEven:(unsigned int *)x { if (x & 1) { return TRUE; } else { return FALSE; } } however whenever I compile it I get the error: Invalid operands to binary % So it's compiling into assembly as a modulus function and failing, somehow, however if...

Shellcode and format string vulnerabilities?

Hi, Here at my job, we have a lot of machines running RH 9, RH Enterprise 3 and some older Linux tastes. As I read about the "format string vulnerability" and "shellcode", I would like to know how to see if that Linux are vulnerable to these kinds of attack (without running the attacks itself)... Thanks for help! ...

How to make every page of a process in the page table present?

i compiled a static program using gcc on linux and run it under kvm. I checked every page table entry of this process in guest memory and found that some pages have been mapped and some ones are not. Is this the feature of on-demand paging? My question is whether there is a solution to make all the pte present and mapped in the page tabl...

How to "typedef" a matrix in C

Hi, when defining new data types in C, one can do typedef double BYTE; so later it is possible to do BYTE length; etc I would like to do something like typedef double[30][30][10] mymatrix; so later I do mymatrix AA[10]; so I have 10 matrices of type mymatrix, and I can access them through AA[0], AA[1], etc Anyway doing...

C: sscanf problem

Hi I have a text file like this: 2 A 10 5 B 31 2 C 6 6 I want to read first line number in a variable and read each line's space separated list of 3 values in 3 variables. I wrote this code: iF=fopen(fileName,"r"); fgets(tmp,255,iF); sscanf(tmp,"%d",&interval); while(!feof(iF)){ cur=(P *)malloc(sizeof(P)); fgets(tmp,255,i...

Server not able to properly read/open a filename sent by client in C

Hi, I'm doing client/server interaction with sockets in C. What I'm trying to do is have the client request a file to be read on the server, the server return a buffer of the file contents, and the client print out the file. Though I was able to accomplish the server sending a buffer of a file to the client & the client printing it out ...

Right way of accessing elements in an array of matrices defined using typedef in C

Hi, I defined a matrix structure in C using typedef double mymatrix[30][30][10]; so now I define an array of them; mymatrix AA[10]; now I tried to access, for a given matrix, the element (i,j,k), so I tried it for AA[5] using AA[5][i][j][k] = 234.0; is this the right way? Thanks ...

Remove first char of string C

Im trying to remove the first char of the string and keep the remainder, my current code doesnt compile and im confused on how to fix it. My code: char * newStr (char * charBuffer) { int len = strlen(charBuffer); int i = 1; char v; if(charBuffer[0] == 'A' || charBuffer[0] == 'Q'){ for(i=1;i<len;i++) ...