C2062 error with power function

Hey -

I wrote a program that works perfectly fine. It tests numbers to see if they are prime, specifically Proth numbers N=(k*(2^n)-1). It takes as input "k" and two values of "n" (upper + lower bounds) and tests all Ns in that range. Simple enough.

Problem is overflows. I eventually need to use arrays, I know.

For the time being, I want to re-write the program as it is to call a 64-bit power function as I have redefined all variables as __int64 instead of int.

Using arrays I should be able to mitigate overflows, but I haven't gotten there yet. The compiler doesn't like my function and I don't understand why. I spent a few hours at it but now I'm stumped.

Here's the cpp:

1
2
3
4
5
6
7
8
9
10
11
12
#include "stdafx.h"

using namespace std;

extern "C++" (__int64 power(__int64 X,__int64 Y) );

void multi(__int64 ,__int64 );
void check (__int64 );

int main()

All the rest of the code...


And, because it's relevant, here's the stdafx.h :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#pragma once

#include "targetver.h"

#include <stdio.h>
#include <tchar.h>
#include <iostream>
#include <stdlib.h>
#include <iomanip>
#include <cmath>
#include <fstream>

using namespace std;

__int64 power(__int64 ,__int64);


I get " error C2062: type '__int64' unexpected "

But I thought I defined it and all that. Why didn't it expect what I told it to expect in the header?

Thanks in advance for any insight.
Remove outermost parentheses

extern "C++" (__int64 power(__int64 X,__int64 Y) );
Last edited on
Also, in some compilers (Everyone maybe, sure VS10 does) a 'long long' is 64-bit.
Last edited on
I am indeed using VS10.

vlad, I did that, and got this in the Build log:

1>GJSieve4.obj : error LNK2019: unresolved external symbol "__int64 __cdecl power(__int64,__int64)" (?power@@YA_J_J0@Z) referenced in function _main
1>c:\......Debug\GJSieve4.exe : fatal error LNK1120: 1 unresolved externals


That is the reason I am using the extern identifier.

I will simply try long long. Maybe that will work.

EDIT: Using "long long" in place of __int64 gives the same error message. As in, the exact same. "error C2062: type '__int64' unexpected"
Last edited on
You forgot to link your library? Don't know .-.
Where is the definition the function power? And I do not understand why do you use the linkage specifier extern "C++"?!
Last edited on
Also try using stdint.h for the 64 bit int type. int64_t

Where are you implementing power?

Try defining the function in your header as

extern __int64 power(__int64,__int64);

EDIT: sorry, just checked there is no stdint.h in msvc
Last edited on
Forget it, I don't need to worry about calling a 64-bit power function...yet.

I re-wrote the whole thing from scratch. It uses arrays now, which is fabulous.

Nope no stdint.h - that I can see anyway.

Yeah, this was a strange problem. Don't worry about it, I'll figure something out.
Topic archived. No new replies allowed.