我正在使用CTest并希望在运行时将命令行参数传递给基础测试.我知道有很多方法可以将命令行参数硬编码到CMake/CTest脚本中,但我想在运行时指定命令行参数,并将这些参数通过CTest传递给基础测试.
这甚至可能吗?
我想知道在什么情况下使用Cygwin编译C代码以及何时会选择MinGW.我找到了Cygwin和MinGW有什么区别?描述Cygwin和MinGW之间的差异.
据我了解,可以说以下内容:
但是,我的理解似乎是错误的,因为我能够使用MinGW编译包含pthread.h的虚拟程序.我错误地理解了什么?
#include <stdio.h>
#include <stdint.h>
#include <stdlib.h>
int main()
{
FILE* bmp = NULL;
uint32_t offset;
uint8_t* temp = NULL;
size_t read;
unsigned int x_dim = 600, y_dim = 388;
bmp = fopen("test_colour.bmp", "r");
if (!bmp)
return -1;
/* Get the image data offset */
fseek(bmp, 10, SEEK_SET);
fgets((char*)&offset, 4, bmp);
printf("Offset = %u\n", offset);
temp = malloc(3*x_dim*y_dim*sizeof(uint8_t));
if (!temp)
return -1;
/* Go the the position where the image data is stored */
fseek(bmp, offset, SEEK_SET);
/* Copy image data …
Run Code Online (Sandbox Code Playgroud) 示例代码test.cpp
#include <array>
#include <string>
int main ()
{
// OK
const std::array<int, 2> array_int = {42, 1337};
std::array<float, array_int.size()> array_float_ok;
// Error
const std::array<std::string, 2> array_string = {"foo", "bar"};
std::array<float, array_string.size()> array_float_error;
return 0;
}
Run Code Online (Sandbox Code Playgroud)
用g ++ 4.8.4编译(Ubuntu 14.04)
g++ -Wall -std=c++0x test.cpp -o test
Run Code Online (Sandbox Code Playgroud)
给出以下错误消息
test.cpp: In function ‘int main()’:
test.cpp:14:39: error: call to non-constexpr function ‘constexpr std::array<_Tp, _Nm>::size_type std::array<_Tp, _Nm>::size() const [with _Tp = std::basic_string<char>; long unsigned int _Nm = 2ul; std::array<_Tp, _Nm>::size_type = long unsigned int]’ …
Run Code Online (Sandbox Code Playgroud) 可能重复:
GCC左移溢出
考虑以下最小程序.
#include <stdint.h>
#include <stdio.h>
int main()
{
uint32_t v = 1024;
v &= (((uint32_t)1 << 32) - 1);
printf("v = %u\n", v);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
这打印1024
正如我预期的那样,在MinGW下用GCC进行编译.因为向左移动32次的1再次为0,因此0-1 = -1,即"1111 ...... 1111".带有任何值的AND'应该再次返回相同的值.
但是,如果我将程序更改为
#include <stdint.h>
#include <stdio.h>
int main()
{
unsigned int s = 32;
uint32_t v = 1024;
v &= (((uint32_t)1 << s) - 1);
printf("v = %u\n", v);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
打印结果现在0
.有人可以解释这种行为吗?
我使用Ctest来运行一堆使用add_test注册的Google测试。当前,这些测试没有任何参数。但是,我想在运行ctest时为它们提供所有参数(所有参数都通用,特别是--gtest_output = xml)。
我听说使用--test-command选项可以做到这一点,但是,我看到我们需要将--test-command和--build-and-test一起使用。有这种用法的例子吗?
我有一个设计,我正在写入/读取RAM并从读取值执行一些计算.在某些情况下,我从RAM位置读取值,我还没有写任何东西.这是故意的,因为在发生这种情况的情况下,未初始化的值不会影响计算:在这些情况下,未初始化的值乘以0.
但是,乘以包含位的unsigned
/ signed
类型会'U'
导致"不关心"输出(即乘法输出的所有位都是'X'
),即使另一个操作数为0.因此,我无法检查我的最终计算输出testbench因为它变得"不关心"(似乎"不关心"输出被解释为0).
为了避免这个问题,我编写了一个函数来解析to中的任何'U'
或'X'
位.功能如下std_logic_vector
'0'
function f(x : std_logic_vector) return std_logic_vector is
variable y : std_logic_vector (x'range);
begin
y := x;
-- pragma synthesis off
for i in 0 to x'length-1 loop
case x(i) is
when 'U' | 'X' => y(i) := '0';
when others => y(i) := x(i);
end case;
end loop; -- i
-- pragma synthesis on
return y;
end;
Run Code Online (Sandbox Code Playgroud)
现在我想通过设置'X'
和'U'
位来扩展功能,'0' …
我有以下代码用于测试如何使用pthread_exit()
和"实现返回值" pthread_join()
.
#include <stdio.h>
#include <pthread.h>
void* busy() {
int returnValue = 2;
pthread_exit((void*)&returnValue);
}
int main() {
void* retVoidPtr = NULL;
int* retValPtr = NULL;
int retVal;
pthread_t busyThread;
pthread_create(&busyThread, NULL, busy, NULL);
pthread_join(busyThread, &retVoidPtr);
retValPtr = (int*) retVoidPtr;
retVal = *retValPtr;
printf("Busy thread returned %d\n", retVal);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
该程序编译良好,但从未得到printf
声明.该行发生了一个段错误retVal = *retValPtr
.使用gdb,我可以看到retValPtr
指针不再,NULL
但是当我尝试print *retValPtr
gdb时说"无法访问地址0x处的内存......".我出错的任何建议?