C++ C++;,C2447';{';:缺少函数头(旧式格式列表?),win32和long

C++ C++;,C2447';{';:缺少函数头(旧式格式列表?),win32和long,c++,cryptography,win32-process,long-long,error-list,C++,Cryptography,Win32 Process,Long Long,Error List,在现有代码上构建解决方案以供学习时,我遇到了一个错误。我定义的预处理器是Win32(它应该是),代码本身就是源代码。错误似乎是由一个long值创建的,该值可能是导致此错误的原因(正在使用的是Win32,而不是win64)。我尝试以不同的方式克服编写此错误(使用long/ulong/int)但未成功 static long long opsCount; void countOps(long n){ opsCount += n; } 有没有建议如何以其他方式写下这篇文章,并在错误列表中解

在现有代码上构建解决方案以供学习时,我遇到了一个错误。我定义的预处理器是Win32(它应该是),代码本身就是源代码。错误似乎是由一个
long
值创建的,该值可能是导致此错误的原因(正在使用的是Win32,而不是win64)。我尝试以不同的方式克服编写此错误(使用
long
/
ulong
/
int
)但未成功

static long long opsCount;

void countOps(long n){
    opsCount += n;
}
有没有建议如何以其他方式写下这篇文章,并在错误列表中解决这一恶劣天气

/* 
 * A runnable main program that calculates and prints the approximate
 * number of 32-bit arithmetic operations needed to perform
 * elliptic curve point multiplication, in this C++ implementation.
 * 
 * Bitcoin cryptography library
 * Copyright (c) Project Nayuki
 * 
 * https://www.nayuki.io/page/bitcoin-cryptography-library
 * https://github.com/nayuki/Bitcoin-Cryptography-Library
 */

#include <cstddef>
#include <cstdlib>
#include <iostream>
#include <string>
#include "CountOps.hpp"
#include "CurvePoint.hpp"
#include "Ecdsa.hpp"
#include "FieldInt.hpp"
#include "Sha256.hpp"
#include "Sha256Hash.hpp"
#include "Uint256.hpp"


static long long opsCount;


void countOps(long n){
    opsCount += n;
}



static void printOps(const char *name);
static void doUint256();
static void doFieldInt();
static void doCurvePoint();
static void doEcdsa();


int main() {
    doUint256();
    doFieldInt();
    doCurvePoint();
    doEcdsa();
    return EXIT_SUCCESS;
}


static void doUint256() {
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x.replace(y, 1);
        printOps("uiReplace");
    }
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x.swap(y, 1);
        printOps("uiSwap");
    }
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x == y;
        printOps("uiEquals");
    }
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x < y;
        printOps("uiLessThan");
    }
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x.add(y);
        printOps("uiAdd");
    }
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x.subtract(y);
        printOps("uiSubtract");
    }
    {
        Uint256 x = Uint256::ONE;
        opsCount = 0;
        x.shiftLeft1();
        printOps("uiShiftLeft1");
    }
    {
        Uint256 x = Uint256::ONE;
        opsCount = 0;
        x.shiftRight1();
        printOps("uiShiftRight1");
    }
    {
        Uint256 x = Uint256::ONE;
        Uint256 y = CurvePoint::ORDER;
        opsCount = 0;
        x.reciprocal(y);
        printOps("uiReciprocal");
    }
    std::cout << std::endl;
}


static void doFieldInt() {
    {
        FieldInt x(Uint256::ONE);
        FieldInt y(Uint256::ONE);
        opsCount = 0;
        x.replace(y, 1);
        printOps("fiReplace");
    }
    {
        FieldInt x(Uint256::ONE);
        FieldInt y(Uint256::ONE);
        opsCount = 0;
        x == y;
        printOps("fiEquals");
    }
    {
        FieldInt x(Uint256::ONE);
        FieldInt y(Uint256::ONE);
        opsCount = 0;
        x < y;
        printOps("fiLessThan");
    }
    {
        FieldInt x(Uint256::ONE);
        FieldInt y(Uint256::ONE);
        opsCount = 0;
        x.add(y);
        printOps("fiAdd");
    }
    {
        FieldInt x(Uint256::ONE);
        FieldInt y(Uint256::ONE);
        opsCount = 0;
        x.subtract(y);
        printOps("fiSubtract");
    }
    {
        FieldInt x(Uint256::ONE);
        opsCount = 0;
        x.multiply2();
        printOps("fiMultiply2");
    }
    {
        FieldInt x(Uint256::ONE);
        FieldInt y(Uint256::ONE);
        opsCount = 0;
        x.multiply(y);
        printOps("fiMultiply");
    }
    {
        FieldInt x(Uint256::ONE);
        opsCount = 0;
        x.square();
        printOps("fiSquare");
    }
    {
        FieldInt x(Uint256::ONE);
        opsCount = 0;
        x.reciprocal();
        printOps("fiReciprocal");
    }
    std::cout << std::endl;
}


static void doCurvePoint() {
    {
        CurvePoint x = CurvePoint::G;
        CurvePoint y = CurvePoint::G;
        opsCount = 0;
        x.replace(y, 1);
        printOps("cpReplace");
    }
    {
        CurvePoint x = CurvePoint::G;
        opsCount = 0;
        x.isZero();
        printOps("cpIsZero");
    }
    {
        CurvePoint x = CurvePoint::G;
        CurvePoint y = CurvePoint::G;
        opsCount = 0;
        x == y;
        printOps("cpEquals");
    }
    {
        CurvePoint x = CurvePoint::G;
        opsCount = 0;
        x.twice();
        printOps("cpTwice");
    }
    {
        CurvePoint x = CurvePoint::G;
        CurvePoint y = CurvePoint::G;
        opsCount = 0;
        x.add(y);
        printOps("cpAdd");
    }
    {
        CurvePoint x = CurvePoint::G;
        Uint256 y = Uint256::ONE;
        opsCount = 0;
        x.multiply(y);
        printOps("cpMultiply");
    }
    {
        CurvePoint x = CurvePoint::G;
        opsCount = 0;
        x.normalize();
        printOps("cpNormalize");
    }
    {
        CurvePoint x = CurvePoint::G;
        opsCount = 0;
        x.isOnCurve();
        printOps("cpIsOnCurve");
    }
    std::cout << std::endl;
}


static void doEcdsa() {
    {
        Uint256 privKey = Uint256::ONE;
        Sha256Hash msgHash = Sha256::getHash(nullptr, 0);
        Uint256 nonce = Uint256::ONE;
        Uint256 outR, outS;
        opsCount = 0;
        Ecdsa::sign(privKey, msgHash, nonce, outR, outS);
        printOps("edSign");
    }
    {
        CurvePoint pubKey = CurvePoint::G;
        Sha256Hash msgHash = Sha256::getHash(nullptr, 0);
        Uint256 r = Uint256::ONE;
        Uint256 s = Uint256::ONE;
        opsCount = 0;
        Ecdsa::verify(pubKey, msgHash, r, s);
        printOps("edVerify");
    }
    std::cout << std::endl;
}


static void printOps(const char *name) {
    std::string s = std::to_string(opsCount);
    while (s.size() < 9)
        s.insert(0, " ", 1);
    for (std::size_t i = s.size(); i >= 4; i -= 3)
        s.insert(i - 3, " ", 1);
    std::cout << s << "  " << name << std::endl;
}
/*
*一种可运行的主程序,计算并打印近似值
*需要执行的32位算术运算数
*椭圆曲线点乘法,在此C++实现。
* 
*比特币密码库
*版权所有(c)Nayuki项目
* 
* https://www.nayuki.io/page/bitcoin-cryptography-library
* https://github.com/nayuki/Bitcoin-Cryptography-Library
*/
#包括
#包括
#包括
#包括
#包括“CountOps.hpp”
#包括“CurvePoint.hpp”
#包括“Ecdsa.hpp”
#包括“FieldInt.hpp”
#包括“Sha256.hpp”
#包括“Sha256Hash.hpp”
#包括“Uint256.hpp”
静态长时间观察;
无效计数操作(长n){
opsCount+=n;
}
静态无效打印操作(常量字符*名称);
静态void doUint256();
静态void doFieldInt();
静态void doCurvePoint();
静态空洞doEcdsa();
int main(){
doUint256();
doFieldInt();
doCurvePoint();
doEcdsa();
返回退出成功;
}
静态void doUint256(){
{
Uint256 x=Uint256::一;
Uint256 y=Uint256::1;
opsCount=0;
x、 替换(y,1);
打印操作(“uiReplace”);
}
{
Uint256 x=Uint256::一;
Uint256 y=Uint256::1;
opsCount=0;
x、 互换(y,1);
printOps(“uiSwap”);
}
{
Uint256 x=Uint256::一;
Uint256 y=Uint256::1;
opsCount=0;
x==y;
打印操作(“uiEquals”);
}
{
Uint256 x=Uint256::一;
Uint256 y=Uint256::1;
opsCount=0;
xstd::cout为了将来的参考,您应该努力使您的示例成为一个好的示例。这不仅会增加您获得堆栈溢出响应的机会,而且很可能会使您自己开始解决问题

例如,这是您遇到问题的单一函数:

#define countOps(n)
static long long opsCount;
void countOps(long n){
    opsCount += n;
}
如果您试图在
.cpp
文件中编译该文件,它会工作,尽管您会抱怨缺少入口点。因此,So
#include
一定会引起问题。显而易见的候选者是
CountOps.hpp
,在这里声明了这一点。在这种情况下,除非您
定义
COUNT\u OPS
,否则头将是just

#define countOps(n)
因此,如果我们将这两部分放在一起,我们就有一个最小的、可重复的编译错误示例:

#define countOps(n)
static long long opsCount;
void countOps(long n){
    opsCount += n;
}
换句话说,包含的文件试图将countOps函数定义为空,通过实现它,预处理器将代码转换为空

static long long opsCount;
void {
    opsCount += n;
}
这没有任何意义。您可以通过在包含
CountOps.hpp
之前定义COUNT\u OPS
来解决此问题,或者干脆不用费心尝试创建此函数。正确的路径取决于此库的使用方式

我的意思不是告诉你如何解决这个问题,而是希望能帮助你理解未来如何检测它,这样你就能理解发生了什么,为什么会发生,或者至少帮助其他试图帮助你的人


最后一点:假设你的图像永远不会被看到。不仅一些用户看不到它们,而且将来搜索你的问题的另一个用户也看不到它们,因此它向其他人传授了从你的问题中学习的能力。你的编译器将在某种程度上在文本中发出这些错误。你应该从中复制粘贴e、

错误是什么?它与天气有什么关系?请发布一条消息,说明代码看起来有效。错误一定来自其他原因。Good point添加了3个错误,这些错误将显示出来,并更新了文件的完整代码。关于坏天气是一个有点糟糕的笑话,因为这需要很多时间和“争论”在网站上添加标签时,我认为更相关的标签被取消,对此表示抱歉。您包含的一个头文件中可能有错误(例如,在类定义后缺少分号)。re:“我还不允许添加图片”--不要发布错误消息的图片。按您的方式发布文本。