标签: cl

C/C++中的括号内的代码块是否合法,MSCL可以编译它吗?

我有以下代码:

int x;
x = ({ 1; 2; 3; });
printf("%d\n", x); // should be 3
Run Code Online (Sandbox Code Playgroud)

(如果你很好奇为什么我会编写那样令人厌恶的代码.答案是我不是.我正在编写一个输出C代码的生成器,并且这样的语句会使事情变得容易多了.)

该代码编译并在Apple LLVM版本7.0.2上运行(当然会对未使用的代码发出警告)但在MSCL 10.0和14.0中失败(错误C2059:语法错误:'{').

我的问题是:1)是否有这种代码的名称(-abuse)?2)在任何C/C++标准中是否合法?3)有没有办法让MSCL接受它?

c c++ gcc-extensions cl

2
推荐指数
1
解决办法
167
查看次数

Python:Windows 10 上的“pip install gmpy”返回“cl.exe' failed with exit status 2”

我已经在 Windows10 上安装了 Pyhton 3.7,当我运行pip install gmpy控制台时,返回这个错误:

Collecting gmpy
  Using cached https://files.pythonhosted.org/packages/26/37/2184c13cee81e1dbeaebbb13570195247e73ab2138a3db0c9d2c5347e372/gmpy-1.17.zip
Building wheels for collected packages: gmpy
  Building wheel for gmpy (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'c:\python37\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\franc\\AppData\\Local\\Temp\\pip-install-du1j9u7s\\gmpy\\setup.py'"'"'; __file__='"'"'C:\\Users\\franc\\AppData\\Local\\Temp\\pip-install-du1j9u7s\\gmpy\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\franc\AppData\Local\Temp\pip-wheel-nz4_kuat' --python-tag cp37
       cwd: C:\Users\franc\AppData\Local\Temp\pip-install-du1j9u7s\gmpy\
  Complete output (12 lines):
  running bdist_wheel
  running build
  running build_ext
  building 'gmpy' extension
  creating build
  creating build\temp.win-amd64-3.7
  creating build\temp.win-amd64-3.7\Release
  creating build\temp.win-amd64-3.7\Release\src …
Run Code Online (Sandbox Code Playgroud)

python pip cl.exe gmpy cl

2
推荐指数
1
解决办法
3007
查看次数

指定 cl.exe 的命令行 C++ 版本 (Visual Studio Code)

我正在 Visual Studio Code 中测试 C++17 Fallthrough属性。IDE 已配置为使用 Microsoft Visual Studio cl.exe 编译器编译 C/C++ 代码。我在调试模式下tasks.json构建简单文件的任务定义(在 )是:.cpp

{
    "type": "shell",
    "label": "cl.exe: Build active file",
    "command": "cl.exe",
    "args": [
        "/Zi",
        "/EHsc",
        "/Fe:",
        "${file}",
        "/link",
        "/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
    ],
    "options": {
        "cwd": "${workspaceFolder}"
    },
    "problemMatcher": [
        "$msCompile"
    ]
}
Run Code Online (Sandbox Code Playgroud)

这已经在多个程序上进行了测试并且效果良好。现在我包含一个switch使用新[[fallthrough]];属性的语句,编译器会生成:

warning C5051: attribute 'fallthrough' requires at least '/std:c++17'; ignored
Run Code Online (Sandbox Code Playgroud)

添加"/std:c++17",到 cl.exe 的“args”没有任何改变(生成相同的编译器警告)。这是新版本:

"args": [
    "/Zi",
    "/EHsc",
    "/Fe:",
    "/std:c++17",
    "${file}",
    "/link",
    "/OUT:${fileDirname}\\${fileBasenameNoExtension}.exe"
],
Run Code Online (Sandbox Code Playgroud)

据我所知,根据Microsoft …

c++ cl visual-studio-code

2
推荐指数
1
解决办法
3370
查看次数

Common Lisp:在 first、rest、last 中解构列表(如 Python 可迭代解包)

David Touretzky 的 Common Lisp 书中的练习 6.36 要求一个函数swap-first-last来交换任何列表的第一个和最后一个参数。我现在觉得很愚蠢,但我无法用destructuring-bind.

我如何在 Pythonfirst, *rest, last = (1,2,3,4)中执行 Common Lisp/with 中的操作(可迭代解包)destructuring-bind

lisp common-lisp cl

2
推荐指数
1
解决办法
343
查看次数

从命令行使用Visual C ++ 2013编译C / SDL程序

我该怎么办?我不想使用Visual Studio IDE,但是我想使用提供的编译器(cl.exe)和VS2013的开发人员命令提示符。

c sdl cl

1
推荐指数
1
解决办法
1402
查看次数

如何使用Visual C ++的内联汇编器插入重复的NOP语句?

使用Microsoft的编译器的Visual C ++,允许我们使用以下命令定义内联汇编代码:

__asm {
    nop
}
Run Code Online (Sandbox Code Playgroud)

我需要的是一个宏,可以将这样的指令乘以n次:

ASM_EMIT_MULT(op, times)
Run Code Online (Sandbox Code Playgroud)

例如:

ASM_EMIT_MULT(0x90, 160)
Run Code Online (Sandbox Code Playgroud)

那可能吗?我该怎么办?

x86 assembly inline-assembly visual-studio cl

1
推荐指数
1
解决办法
647
查看次数

现有文件和正确路径的“无法打开源文件”错误

我正在构建一些自定义 Qt 组件作为静态库,但我无法通过编译阶段。我的项目结构如下:

Root:
 - .h and . cpp files of the custom Qt components
 - GeneratedFiles/Debug/ <-- here the MOC compiler puts the generated moc_*.cpp files ("Debug" is automatically deducted from the build configuration, so it's Release for release builds)
Run Code Online (Sandbox Code Playgroud)

这是一个非常标准的文件夹设置,但无论出于何种原因,编译器都无法找到moc 文件。根文件夹中的任何内容都可以正常构建,但找不到 moc 文件。请注意,moc_ 文件生成得很好并且存在于它们应该存在的地方,具有正确的内容。问题似乎出在路径的评估上GeneratedFiles\Debug\moc_whatever.cpp

有趣的是,如果我moc_example.cpp在根文件夹中移动一个 moc 文件(比如)并手动调整调用CL.exe以 compilemoc_example.cpp而不是GeneratedFiles\Debug\moc_example.cpp,该文件就会被构建。

我正在使用 VS 2017 版本 15.7.1,CL 是 x64 版本 19.00.24215.1,我会用任何其他可能有用的细节更新问题,只需在评论中添加询问。

那么......为什么编译器告诉我这些文件不存在?

c++ msbuild qt cl

1
推荐指数
1
解决办法
1150
查看次数

显然,cl.exe编译器接受了错误的C++代码

我想知道为什么Visual Studio 2012中的Microsoft cl.exe编译器接受以下C++代码?

int x;
struct A {}
decltype(x) y;
Run Code Online (Sandbox Code Playgroud)

这看起来像是一个明显的错误,但上面的代码是可编译的.但请注意,以下代码被正确拒绝:

int x;
struct A {}
int y;
Run Code Online (Sandbox Code Playgroud)

c++ cl

0
推荐指数
1
解决办法
148
查看次数

编译器警告-参数列表有所不同

我正在尝试编译以下源代码,这些源代码可以在gccMicrosoft和Microsoft上成功编译cl.exe

void SomethingBeforeExit();

void SomethingBeforeExit()
{
    // some code
    _exit(0);
}

int main(int argc, char *argv[])
{
    // some code
    atexit(SomethingBeforeExit);
}
Run Code Online (Sandbox Code Playgroud)

但是,我从以下消息中收到C4113警告cl.exe

SomeCode.c(10): warning C4113: 'void (__cdecl *)()' differs in parameter lists from 'void (__cdecl *)(void)'
Run Code Online (Sandbox Code Playgroud)

正如我所说,源代码仍然可以成功编译并且可以正常工作。我的目标是防止在中发生此警告cl,因为gcc在编译时不会生成任何警告。

我假设该函数的声明未被视为void SomethingBeforeExit(void),但是,我不知道如何将函数的参数列表明确声明为void

我正在使用VS14and C/C++ 19.00.23918 for x86for cl.exegcc v5.4.0编译器来比较生成的警告。

c gcc visual-studio cl

0
推荐指数
1
解决办法
608
查看次数

有没有办法在GCC或cl.exe的预处理和编译之间插入一个步骤?

我正在尝试设置一个大的C代码库.代码库可以使用GCC和MS cl.exe构建.代码库包含数百万行.我正在尝试将其用于代码覆盖.因为运行时环境很特殊,所以我必须以特殊的方式进行检测.

我编写了一个可以执行检测的转换工具.但是它无法处理宏扩展,头文件包括等等.换句话说,它必须在预处理阶段之后工作.

我可能没有足够的时间来编写C预处理器.由于代码库是使用GCC/cl.exe构建的,我想知道是否可以将我的转换步骤注入GCC或cl.exe编译过程.像这样:

GCC/cl.exe pre-process  ->  (My transformation) -> GCC/cl.exe compilation
Run Code Online (Sandbox Code Playgroud)

那可能吗?

添加1

到目前为止,所有答案都围绕着海湾合作委员会.怎么样的Microsoft cl.exe?我尝试了/ P选项,它将预处理结果发送到文件.但结果包含许多行,如下所示:

#line 1306 "<some file path>"
Run Code Online (Sandbox Code Playgroud)

我想解决它.

好的,我解决了.指定两者/P/EP可以禁止#line指令.

添加2

两个指定的输出"/P /EP"cl.exe是一个*.i没有文件#line的指令.这是一个有效的C源文件.所以它可以直接输入cl.exe.我只是重命名原始的C文件并使用该*.i文件进行检测,然后使用构建过程.

(注意避免包含一些头文件/FI.这可能会导致一些重复的定义错误.应该删除它们,因为它们的内容已经包含在*.i文件中.)

添加3

我可以使用/P开关.该#line指令不会危害编译,并且可以被C解析器识别.如cJonathan Leffler所指出的那样,如果没有这些信息,很难从仪表代码回溯到原始源代码.

添加4

仪器仪表并不容易.例如,根据此处的基于块的代码覆盖的块分离是棘手的(注意块4).

c gcc cl

0
推荐指数
1
解决办法
65
查看次数

为什么`警告C4804:'>':在操作中不安全地使用类型'bool'在Visual Studio 2015上弹出?

为什么warning C4804: '>': unsafe use of type 'bool' in operation在Visual Studio 2015上弹出?

如果您运行此代码:

#include <iostream>
#include <cstdlib>

int main( int argumentsCount, char* argumentsStringList[] )
{
#define COMPUTE_DEBUGGING_LEVEL_DEBUG      0
#define COMPUTE_DEBUGGING_DEBUG_INPUT_SIZE 32

    int inputLevelSize;
    int builtInLevelSize;

    inputLevelSize   = strlen( "a1" );
    builtInLevelSize = strlen( "a1 a2" );

    if( ( 2 > inputLevelSize > COMPUTE_DEBUGGING_DEBUG_INPUT_SIZE )
        || ( 2 > builtInLevelSize > COMPUTE_DEBUGGING_DEBUG_INPUT_SIZE ) )
    {
        std::cout << "ERROR while processing the DEBUG LEVEL: " << "a1" << std::endl;
        exit( …
Run Code Online (Sandbox Code Playgroud)

c++ cl visual-studio-2015

-1
推荐指数
1
解决办法
3788
查看次数

如何关闭Microsoft编译器(cl)中的异常?

我用什么编译器标志来完全摆脱异常处理?我根本不使用它们,但编译器仍然生成.pdata和.xdata部分,仅用于异常处理.

c++ visual-c++ cl

-2
推荐指数
2
解决办法
1707
查看次数

我找到了一个用C编写的base64解码器。当我用GCC编译它时它工作正常。但是cl.exe出错了。为什么?

/**
 * Copyright (c) 2006-2018 Apple Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, …
Run Code Online (Sandbox Code Playgroud)

c gcc cl

-3
推荐指数
1
解决办法
112
查看次数