Hello there,

I have the following C code (this one removes adjacent duplicates in a string):
    
    
    // myccode.c
    const char* change(char *str) {
        int i=1;
        int j=1;
        int k;
        int d=0;
        
        while(str[i]!='\0') {
             if(str[i-1]==str[i]) {
                 k=i+1;
                while(str[k]!='\0'&&str[k-1]==str[k]) {
                     k++;
                 }
                 i=k;
              }
            str[j]=str[i];
             j++;
             i++;
        }
        str[j]='\0';
        
        return str;
    }

I am compiling it with GCC myccode.c -C

Once I have the myccode.o ready to go, I am running the following Nim code:
    
    
    {.compile: "myccode.c".}
    proc change(a: cstring): cstring {.importc.}
    
    when isMainModule:
      echo change("Hellllo Thereee !!")
    

However, I am getting the error: SIGSEGV: Illegal storage access. (Attempt to 
read from nil?) Error: execution of an external program failed:...

My environment: Windows 10, mingw, nim 0.15

All the best, Alfred N

Reply via email to