-2

I have run this code on another Linux environment where it works, but when I run this code on my machine it shows an error.

The code is:

void *functionC(void* ptr)
{
    dint* pointer=(int*)ptr;
    pthread_mutex_lock( &mutex1 );
    int i;
    for( i=pointer[0]; i <= pointer[1]; i++ )
    {
        sum += myarray[i];
    }
    pthread_mutex_unlock( &mutex1 );
}  

The error I got in my machine is:

aftab@aftab-VirtualBox:~/Downloads$ gcc -o out done1.c -lpthreads
done1.c: In function ‘functionC’:
done1.c:59:2: error: unknown type name ‘dint’
dint* pointer=(int*)ptr;
SOReader
  • 5,697
  • 5
  • 31
  • 53
pithoro
  • 1
  • 1
  • 4
    Where is `dint` defined? – stark Oct 09 '17 at 17:17
  • int a function : void *functionC(void* ptr) { int* pointer=(int*)ptr; pthread_mutex_lock( &mutex1 ); for(int i=pointer[0];i<=pointer[1];i++) { pointer[2] += myarray[i]; } pthread_mutex_unlock( &mutex1 ); } – pithoro Oct 09 '17 at 17:27
  • 1
    Don't paste code inside comments, as it is not very readable. Please edit your post with the code (and format the code). – Thomas Matthews Oct 09 '17 at 17:37
  • What is the *type* of `dint`? – Thomas Matthews Oct 09 '17 at 17:38
  • dint* pointer=(int*)ptr; – pithoro Oct 09 '17 at 17:41
  • 2
    That's not defining `dint`. It is using `dint` without defining it. – stark Oct 09 '17 at 17:45
  • In your original post, you list: dint* pointer=(int*)ptr; Yet in your comment-pasted version you list: int* pointer=(int*)ptr; Is dint a type that is declared elsewhere? Please format your code more cleanly and add some more context when asking questions like this. It will make it easier for others to understand and get you an answer. – Stuart Thompson Oct 09 '17 at 18:13

1 Answers1

1

The error that gcc is complaining about is that there is an unknown type name ‘dint’.

There is no basic type dint in c++, so it must be declared somewhere.

In the version of the code you are copying from there is probably either a typedef or a header file that you haven't included.

From a little looking, I don't see any reference to a dint in pintos, so it's probably defined somewhere in the original file.

Look for a line like:

typdef int dint;
unDeadHerbs
  • 1,306
  • 1
  • 11
  • 19
  • ...or that "d" in "dint" is a typo to begin with, that happened during copy & paste of the code or somesuch... – DevSolar Oct 16 '17 at 21:19