Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpreter errors handing STL objects in functions #514

Open
koziscool opened this issue Jan 23, 2024 · 2 comments
Open

Interpreter errors handing STL objects in functions #514

koziscool opened this issue Jan 23, 2024 · 2 comments

Comments

@koziscool
Copy link

Eg, this code:

void Eratosthenes(vector<long int>* primes, long int limit){
    vector<bool> primeArray(limit, true);
    for( long int p = 2; p < sqrt(limit); p++){
        if( primeArray[p]){
            for(long int m = p*p; m < limit; m += 2 * p)
                primeArray[m] = false;
        }
    }

    primes->push_back(2);
    for( long int j = 3; j < limit; j ++ 2 ){
        if (primeArray[j])
            primes->push_back(j);
    }
}

produces this error:

input_line_9:10:42: error: expected ')'
    for( long int j = 3; j < limit; j ++ 2 ){
                                         ^
input_line_9:10:8: note: to match this '('
    for( long int j = 3; j < limit; j ++ 2 ){
       ^

Interpreter Error: 

Btw, that code seems to run just fine on gcc.

@koziscool
Copy link
Author

This code has a basic typo in it, the interpreter runs it fine (when edited correctly). Should I delete this, or leave it here in case I reproduce a similar error?

@koziscool
Copy link
Author

Ok so here might be a better example, that's not a typo

long int e10(vector<long int>* primes, int limit){
    long int total = 0;
    vector<long int>::iterator: i = primes->begin();
    while( *i < limit ){
        total += *i;
        i++;
    } 
    return total;
}

Here the interpreter says:

input_line_14:2:51: error: function definition is not allowed here
 long int e10(vector<long int>* primes, int limit){
                                                  ^

Interpreter Error: 

again runs fine on gcc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant