Processes & threads C programming on Windows: trouble with command line arguments -


i'm working processes , threads on c language via netbeans (with windows 7). i'm using command line arguments when cames run program there's no way work. if use run netbeans button won't ask arguments need enter , display message:

/cygdrive/c/program files/netbeans 8.1/ide/bin/nativeexecution/dorun.sh: line 33: 3592 segmentation fault (core dumped) sh "${shfile}"

i'm trying use cmd console seems i'm making wrong calling function way:

gcc ej1.c 2

i'm supposed use format:

gcc font_file.c -o exe_file.exe

but there's no .exe file on netbeans folder far know. here's message when running through windows cmd.

and here's code:

#include <stdio.h> #include <stdlib.h> #include <windows.h>  int main(int argc, char *argv[]) {     handle hthread2;     dword idthread2;     int n = atoi(argv[1]);     printf("parĂ¡metro: n = %d\n\n",n);      printf("soy el proceso %d\n",(int)getcurrentprocessid());     printf("comienza el hilo primario (id %d)\n\n",(int)getcurrentthreadid());       void func(int *n){         printf("comienza el hilo secundario (id %d)\n",(int)getcurrentthreadid());         int i;         int var = 0;         for(i=0; i<*n; i++){             var++;         }         printf("valor final de la variable: %d\n",var);         printf("finaliza el hilo secundario (id %d)\n\n",(int)getcurrentthreadid());     }        hthread2 = createthread (null,                             0,                             (lpthread_start_routine) func,                             &n,                             0,                             &idthread2);      waitforsingleobject(hthread2, // este es el descriptor dell objeto por el que se espera                         infinite);      closehandle(hthread2);      printf("finaliza el hilo primario (id %d)\n",(int)getcurrentthreadid());     return 0; } 

function createthread requires third parameter of type threadproc, function pointer of type dword(*)(lpvoid) .

dword unsigned 32 bit integer , lpvoid pointer void.

the function code passes createthread has type void(*)(int*), types incompatible.

c standard states calling function through function pointer not compatible function type, result in undefined behavior. manifest segmentation fault.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -