有什么东西可以在C中完成但在C++中没有,在C++编码时你最想念的是哪些?
我能想到的几件事情:
编辑:感谢@sbi指出:
1.应该是:我们可以为C中的任何类型的指针分配void指针,但不能在C++中
如何将c99源代码自动转换为c89?我想用Visual C++编译c99库,但MSVC只支持c89.许多更改只是语法,例如struct initializers,您可以自动编写"de-c99"代码的工具.这个预处理器是否存在?
请参阅以下wiki文本:
C99标准包括几种新整数类型的定义,以增强程序的可移植性[2].已经可用的基本整数类型被认为是不够的,因为它们的实际大小是实现定义的并且可能在不同系统之间变化.新类型在嵌入式环境中特别有用,在这些环境中,硬件通常只支持几种类型,并且支持因系统而异.所有新类型都在inttypes.h头文件中定义(C++中的cinttypes头文件),也可以在stdint.h头文件中找到(C++中的cstdint头文件).这些类型可以分为以下几类:
我的visual studio找不到这些文件:
<cstdint><cinttypes><stdint.h><inttypes.h>为什么?
是否有一个编译器能够很好地支持新的C++ 0x?
我使用GCC,但遗憾的是当前版本4.4对新功能的支持不足.
他们都遵循2003年发布的C++ 03吗?
我不知道从Visual Studio 2010收到这些错误的原因.
这是我的程序从第343行到第408行的代码:
int create_den_from_img(char *img_file_name_part, int xlen, int ylen, int zlen )
{
IplImage* imgs = 0;
char str[80];
unsigned char *data,*imgdata;
/* allocating memory */
data = (unsigned char *) malloc(xlen * ylen * zlen * sizeof(unsigned char) );
if(data==NULL)
{
printf("error in allocating memory \n");
exit(1);
}
/* Getting the filename & iterating through tiff images */
for(int k = 0; k < zlen; k++)
{
int count=2;
int tmp=k+1;
while(tmp/10)
{
count=count-1;
tmp=tmp/10;
}
switch(count) …Run Code Online (Sandbox Code Playgroud) 在代码审查中,我要求使用下面的选项(1),因为它导致创建符号(用于调试),而(2)和(3)似乎至少对gcc和icc没有这样做.但是(1)不是真正的const,不能在所有编译器上用作数组大小.有没有更好的选项,包括调试符号,真的是C的常量?
符号:
gcc f.c -ggdb3 -g ; nm -a a.out | grep _sym
0000000100000f3c s _symA
0000000100000f3c - 04 0000 STSYM _symA
Run Code Online (Sandbox Code Playgroud)
码:
static const int symA = 1; // 1
#define symB 2 // 2
enum { symC = 3 }; // 3
Run Code Online (Sandbox Code Playgroud)
GDB输出:
(gdb) p symA
$1 = 1
(gdb) p symB
No symbol "symB" in current context.
(gdb) p symC
No symbol "symC" in current context.
Run Code Online (Sandbox Code Playgroud)
而为了完整性,来源:
#include <stdio.h>
static const int symA = 1;
#define symB …Run Code Online (Sandbox Code Playgroud) 可能的重复:
C 中的变量声明位置
我真的不明白为什么当我在下面的代码片段中声明变量 'm' 时为什么它不起作用?我在使用它之前声明了 m 那么有什么意义?谢谢
int main(){
int a[] = {2,-4,6,47,59,-6,0};
sort(a, 7);
int m;
for(m = 0; m < 7; m++){
printf("%d ",a[m]);
}
}
Run Code Online (Sandbox Code Playgroud)
但是,如果我将声明放在数组上方的开始处,它就可以工作。
任何人都可以解释为什么这个代码编译:
#include <stdio.h>
#include <string.h>
int main (int argc, char *argv [])
{
FILE *ptr;
char string[10] = "Testing";
ptr = fopen("C:\\Users\\Jordan\\Desktop\\Hello.txt", "wb");
fwrite(string,sizeof(string[0]), sizeof(string)/sizeof(string[0]), ptr);
}
Run Code Online (Sandbox Code Playgroud)
然而,这不会:给出错误C2065:'string':未声明的标识符
#include <stdio.h>
#include <string.h>
int main (int argc, char *argv [])
{
FILE *ptr;
ptr = fopen("C:\\Users\\Jordan\\Desktop\\Hello.txt", "wb");
char string[10] = "Testing";
fwrite(string,sizeof(string[0]), sizeof(string)/sizeof(string[0]), ptr);
}
Run Code Online (Sandbox Code Playgroud)
我在Windows 7计算机上使用Visual Studio 2010.
谢谢
以下代码使用gcc -std = c99在Linux上编译正常但在Visual Studio 2010 C编译器上获得以下错误:
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 16.00.40219.01 for 80x86 Copyright (C) Microsoft Corporation. All rights reserved. fib.c fib.c(42) : error C2057: expected constant expression fib.c(42) : error C2466: cannot allocate an array of constant size 0 fib.c(42) : error C2133: 'num' : unknown size
用户输入要生成的斐波那契数量.我很好奇微软编译器为什么不喜欢这段代码.
#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
void fib(int max);
int main(int argc, char *argv[])
{
int argument;
if (argc != 2)
{
puts("You must supply exactly one …Run Code Online (Sandbox Code Playgroud) 我正在参加编程,我有一位不太参与的教授.不幸的是,这个课程充满了像我这样的新手,所以没有帮助.我必须使用输入/输出,赋值语句和算术创建一个税收计算器.我的朋友实际上帮我修改了一些代码并在发送给我之前编译了它.我没有改变任何东西,但它对我不起作用.
#include <stdio.h>
#include <stdlib.h>
int main()
{
const double TAX_RATE = 0.075;
double item1 = 0, item2 = 0, item3 = 0;
printf("Enter the price of the first item: \n");
scanf("%lf", &item1);
printf("You entered %.2lf \n", item1);
printf("Enter the price of the second item: \n");
scanf("%lf", &item2);
printf("You entered %.2lf \n", item2);
printf("Enter the price of the third item: \n");
scanf("%lf", &item3);
double total = item1 + item2 + item3;
double tax = total * TAX_RATE;
double totalWithTax = …Run Code Online (Sandbox Code Playgroud)