Tag: visual studio 2012

函数调用后无法定义变量

我有很好的C ++经验,现在我正在尝试用纯粹的C做一些事情。但我注意到一个非常奇怪的事实。 以下代码: #include int main() { double a; scanf_s(“%lf”, &a); double b; b = a + 1; printf(“%lf”, b); return 0; } 在sourceLair中编译OK(使用gcc编译器,我知道),但在Microsoft Visual Studio中生成以下错误(使用Visual C ++): 1>Task 1.c(8): error C2143: syntax error : missing ‘;’ before ‘type’ 1>Task 1.c(9): error C2065: b: undeclared identifier 1>Task 1.c(9): warning C4244: =: conversion from ‘double’ to […]

错误C2059:语法错误’常数’

我在头文件中有以下代码: enum {false,true}; 我在main.c中有我的主要function。 如果我将扩展名更改为main.cpp,我会收到以下错误: Error C2059: syntax error ‘constant’ 我使用visual c ++,任何想法为什么`?

Valgrind:无效读取大小4 – > sigsegv,没有valgrind和视觉工作室工作正常

我已经实现了一种压缩算法(使用霍夫曼编码),它使用节点的优先级队列(我定义的结构)。 现在,当我在linux或visual studio中运行代码时,一切正常。 当我检查visual studio中的内存泄漏时,没有给出。 现在的问题是,当我使用valgrind分析我的程序时,它终止于信号11(sigsegv)。 遇到的第一个错误是方法delete min中的“无效读取大小4”。 之后的其他错误是:Adress在大小为453的块中释放0字节,无效写入大小4,无效释放,删除或重新分配。 任何人都可以给我一些关于我可能犯的错误的建议吗? 我一直在互联网上搜索几个小时,但找不到我做错了什么(特别是因为它在没有使用valgrind时才起作用)。 或者提示如何调试并找出导致读取错误的原因。 非常感谢! 这是代码,以防有人想要查看它,但我想这并不是那么容易潜入这个特定的代码。 我猜它与代码的优先级队列有关: 我做霍夫曼部分的部分 – >每次删除2个最小节点并将两者的总和作为一个节点添加。 while(queue->size > 1){ node* n1 = delete_min(queue); node* n2 = delete_min(queue); // all the errors are encountered in this call node* temp = (node*) calloc(sizeof(node),1); temp->amount = n1->amount + n2->amount; insert_node(queue,temp); n1->parent = temp; n2->parent = temp; […]

getchar()跳过C中的所有其他char

我在C中完全使用getchar()已经有一段时间了。在这种情况下,我试图读取一行并将该行的char放入数组中。 但是,在将getchar()分配给数组时,它会跳过一些字符。 例如,输入“它会相互跳过”,输出是…… \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n \ n (\ n只是代表新行。) int N = 0; char message[80] = {}; do { […]

C中未声明的标识符

我正在尝试在Visual Studio 2012 Express中用C编译一个小型银行程序。 它向我显示了几乎所有变量的这个错误“未声明的标识符”,这也是“语法错误:缺少’;’ 在’type’之前。“请告诉我正确的语法。谢谢。 #include #include int main() { printf(“Welcome to skybank\n”); int deposit,withdraw,kbalance; char option; printf(“Press 1 to deposit cash\n”); printf(“Press 2 to Withdraw Cash\n”); printf(“Press 3 to Know Your Balance\n”); scanf_s(“%c”,option); int decash,wicash; switch(option) { int balance; printf(“Enter your current Balance\n”); scanf_s(“%d”,&balance); case 1: printf(“Enter the amount you want to deposit\n”); […]

OpenSSL 1.1.0中的EVP_get_cipherbyname和“undefined struct / union evp_cipher_st”

我正在尝试将openssl与visual studio c项目一起使用。 我使用visual studio nmake命令编译openssl,然后使用以下命令将所有内容安装到预定义文件夹(C:\ openssl): nmake install 文件夹结构如下: bin include/openssl lib 在include / openssl里面有.h头文件。 在我的Visual Studio 2012中,我创建了一个空的通用c ++项目,并包含C:\ openssl \ include [Project properties -> C/C++ -> General -> Additional Include Directories] 我还添加了lib目录和.lib文件。 但是当我编译代码时,我得到了 left of ‘key_len’ specifies undefined struct/union ‘evp_cipher_st’ 在我的代码中,我有这些行 const EVP_CIPHER *cipher = EVP_get_cipherbyname(“aes-256-cbc”); //some other code return cipher->key_len; 查看ossl_typ.h文件以获取evp_cipher_st定义,它被声明为 typedef […]

优化Microsoft Visual Studio编译器生成的程序集

我正在开发一个矩阵乘法项目。 我已经能够编写C代码,并且我能够使用Microsoft visual studio 2012编译器为它生成汇编代码。 编译器生成的代码如下所示。 编译器使用了SSE寄存器,这正是我想要的,但它不是最好的代码。 我想优化这段代码并用C代码内联编写,但我不理解汇编代码。 基本上汇编代码仅适用于矩阵的一个维度,下面的代码仅适用于4乘4矩阵。 我怎样才能使它对n * n矩阵大小有益。 C ++代码如下所示: #define MAX_NUM 10 #define MAX_DIM 4 int main () { float mat_a [] = {1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, 4.0}; float mat_b [] = {1.0, 2.0, 3.0, 4.0, 1.0, 2.0, 3.0, […]

如何禁用Visual Studio 2012的警告?

我有这个错误: 错误C4996:’fopen’:此函数或变量可能不安全。 考虑使用fopen_s代替。 要禁用弃用,请使用_CRT_SECURE_NO_WARNINGS。 详细信息请参见在线帮助。 当我使用其他旧的C函数时会弹出类似的错误。 我的问题是:是否有一种方法可以将这些错误显示为警告,而不会实际阻止代码编译?

C / C ++:sizeof(short),sizeof(int),sizeof(long),sizeof(long long)等…在32位机器上而不是在64位机器上

我正在运行Windows 7(64位)。 这个问题看的是这里发现的同一个问题: 长在64位机器上 但更深入,因为它处理更多的数据类型并适用于C或C ++,而不是C#。 首先,我使用的是Microsoft Visual Studio Ultimate 2012.不幸的是,虽然这个IDE支持C#和Visual C ++,但它似乎不再支持普通的旧版Visual C. 无论如何,我已经尝试在IDE中创建以下标准C ++程序: #include int main(int argc, char **argv) { printf(“sizeof(short): %d\n”, (int) sizeof(short)); printf(“sizeof(int): %d\n”, (int) sizeof(int)); printf(“sizeof(long): %d\n”, (int) sizeof(long)); printf(“sizeof(long long): %d\n”, (int) sizeof(long long)); printf(“sizeof(size_t): %d\n”, (int) sizeof(size_t)); printf(“sizeof(void *): %d\n”, (int) sizeof(void *)); printf(“Hit enter to exit.\n”); […]

如何在Visual Studio中“模拟”C99以进行变量声明

我正在使用Visual Studio 2012开发简单的Win32 C程序。 我知道VS编译器只支持C89,但我想知道是否有办法覆盖这个限制。 特别是我想在我的代码中的任何地方声明变量,而不是仅在范围块的开头声明(如C89所要求的)。 提前致谢。