Why is this program's output different between C and C++?

Possible Duplicate: Size of character ('a') in C/C++ The following program #include <stdio.h> int main() { printf("%dn", sizeof('')); printf("%dn", sizeof(0)); } compiled with gcc outputs 4 4 and with g++ 1 4 Why is this happening? I know this it's not a compiler thing but a difference between C and C++ but what's the reason? In C, character constants h

为什么这个程序的输出在C和C ++之间是不同的?

可能重复: C / C ++中字符的大小('a') 以下程序 #include <stdio.h> int main() { printf("%dn", sizeof('')); printf("%dn", sizeof(0)); } 用gcc输出编译 4 4 和g ++ 1 4 这是为什么发生? 我知道这不是编译器,而是C和C ++之间的区别,但是原因是什么? 在C中,字符常数具有类型int标准的每6.4.4.4(10), 整数字符常量的类型为int。 包含映射到单字节执行字符的单个字符的整数字

Why would the order of linking libs cause runtime errors?

I have an unmanaged C++ project, which produces runtime errors when the linker libraries (Properties->Linker->Input->Additional Dependencies) are listed in a specific order but runs fine when I change the order of libraries. I understand why the order could cause Link errors (Why does the order in which libraries are linked sometimes cause errors in GCC?) but how could it possibly cause

为什么连接库的顺序会导致运行时错误?

我有一个非托管C ++项目,当链接程序库(Properties-> Linker-> Input-> Additional Dependencies)按特定顺序列出,但在更改库的顺序时运行良好时,会产生运行时错误。 我明白为什么命令可能导致链接错误(为什么链接库的顺序有时会导致GCC错误?),但它怎么会导致运行时错误呢? 我在VS2005,2008和2010年观察到了这一点。 什么样的运行时错误? 你不说,所以我们必须猜测。 以下是运行时错误发生的一种方式:

linker problem with libstdc++.so.6 in connection with cuda

today i encountered a problem with linking my compiled cuda stuff. i have a uptodate debian testing w/ 2.6.32-3-amd64. i worked all day on my code. compiling from time to time. had no problem. but then after a minor code change i got following error: gcc -o pa CUDA.o histogram256.o histogram64.o main.o -lrt -lm -lcudart -I. -I/data/cuda/include -I/data/cuda/C/common/inc -L/data/cuda

与cuda有关的libstdc ++。so.6的链接器问题

今天我遇到了连接我编译的cuda的问题。 我有一个uptodate debian测试w / 2.6.32-3-amd64。 我整天在我的代码上工作。 不时编译。 没有问题。 但后来一个小的代码更改后,我得到以下错误: gcc -o pa CUDA.o histogram256.o histogram64.o main.o -lrt -lm -lcudart -I. -I/data/cuda/include -I/data/cuda/C/common/inc -L/data/cuda/lib64 /usr/bin/ld: main.o: undefined reference to symbol 'std::basic_ifstre

C++ unresolved external symbol

Hi iam begginer at c++ i have class with static methods and i cant access them it throws me an error 1>------ Build started: Project: CPractice, Configuration: Debug Win32 ------ 1> Source.cpp 1>Source.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > CPractice::

C ++无法解析的外部符号

您好iam begginer在c + +我有静态方法的类,我不能访问它,它会引发一个错误 1>------ Build started: Project: CPractice, Configuration: Debug Win32 ------ 1> Source.cpp 1>Source.obj : error LNK2001: unresolved external symbol "private: static class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > CPractice::name" (?name@CPractice@@0V?$b

compiling c++ with gcc/g++ compiler

I'm new to c++ and i want to compile my testprogram . i have now 3 files "main.cpp" "parse.cpp" "parse.h" how can i compile it with one command? Compile them both at the same time and place result in a.out $ g++ file.cpp other.cpp Compile them both at the same time and place results in prog2 $ g++ file.cpp other.cpp -o prog2 Compile each separately and

用gcc / g ++编译器编译c ++

我是新来的C ++,我想编译我的测试程序。 我现在有3个文件“main.cpp”“parse.cpp”“parse.h” 我怎样才能用一个命令编译它? 在同一时间编译它们并将结果放入a.out $ g++ file.cpp other.cpp 同时编译它们并将结果放在prog2中 $ g++ file.cpp other.cpp -o prog2 分别进行编译,然后将它们链接到a.out中 $ g++ -c file.cpp $ g++ -c other.cpp $ g++ file.o other.o 分别进行编译,然后将它们链接到prog2 $ g++ -c file

Is g++ both a c++ compiler and a linker?

I was looking at the output from my build in Eclipse. I'm cross compiling for a ColdFire processor. The compilation line looks like this: m68k-elf-g++ -O2 -falign-functions=4 -IC:nburninclude -IC:nburnMOD52... followed by more include file, obvious "compiler" flags and finally the one source file I changed. The next line invokes the same tool again: m68k-elf-g++ srcmain.o srcT

g ++既是c ++编译器又是链接器?

我正在查看Eclipse中构建的输出。 我正在交叉编译ColdFire处理器。 编译线如下所示: m68k-elf-g++ -O2 -falign-functions=4 -IC:nburninclude -IC:nburnMOD52... 其次是更多的包含文件,明显的“编译器”标志,最后是我更改的源文件。 下一行再次调用相同的工具: m68k-elf-g++ srcmain.o srcTouchPanelMediator.o srcStartup.o.... 其次是更多.o文件一些.ld文件和一些.a文件。 这似乎将所有不同类型的目标文件链接在一起

How to compile a c++ program in Linux?

I made a file hi.cpp and I wrote the command given below: #include <iostream> using namespace std; int main () { cout << "Hello World! "; cout << "I'm a C++ program"; return 0; } then I ran it in my RHEL 6 machine with the following command gcc hi.cpp and I got some errors which are as follows: [chankey@localhost ~]$ gcc hi.cpp /tmp/cc32bnmR.o: In function `main': hi.

如何在Linux中编译c ++程序?

我创建了一个hi.cpp文件,并且我写了下面给出的命令: #include <iostream> using namespace std; int main () { cout << "Hello World! "; cout << "I'm a C++ program"; return 0; } 然后使用以下命令将它运行在RHEL 6机器中 gcc hi.cpp 我得到了一些错误,如下所示: [chankey@localhost ~]$ gcc hi.cpp /tmp/cc32bnmR.o: In function `main': hi.cpp:(.text+0xa): undefined reference to `std:

"g++" and "c++" compiler

I just found on my Ubuntu, there are two different C++ compiler: /usr/bin/g++ and /usr/bin/c++. I am not familiar with the latter, but man c++ just jumps to the manpage of gcc. I wonder what is their difference as C++ compilers? Thanks and regards! This is typical Ubuntu symlink mayhem. If you ls -l /usr/bin/c++ , you will see it is actually a symbolic link. to: /etc/alternatives/c++ W

“g ++”和“c ++”编译器

我在我的Ubuntu上发现,有两种不同的C ++编译器:/ usr / bin / g ++和/ usr / bin / c ++。 我不熟悉后者,但man c ++只是跳转到gcc的manpage。 我不知道它们与C ++编译器有什么不同? 感谢致敬! 这是典型的Ubuntu符号链接混乱。 如果你使用ls -l /usr/bin/c++ ,你会发现它实际上是一个符号链接。 至: /etc/alternatives/c++ 而这又是一个符号链接: /usr/bin/g++ 所以,在Ubuntu系统上,c ++是g ++。 链接间

Compiling a C++ program with gcc

Question: How to compile a C++ program with gcc compiler? info.c: #include<iostream> using std::cout; using std::endl; int main() { #ifdef __cplusplus cout << "C++ compiler in use and version is " << __cplusplus << endl; #endif cout <<"Version is " << __STDC_VERSION__ << endl; cout << "Hi" << __FILE__ << __LINE__ <&l

用gcc编译一个C ++程序

问题:如何用gcc编译器编译C ++程序? info.c: #include<iostream> using std::cout; using std::endl; int main() { #ifdef __cplusplus cout << "C++ compiler in use and version is " << __cplusplus << endl; #endif cout <<"Version is " << __STDC_VERSION__ << endl; cout << "Hi" << __FILE__ << __LINE__ << endl; } 当我尝试

GCC: Undefined reference to vtable

This question already has an answer here: What is the difference between g++ and gcc? 10 answers GCC 4.5.2 Linker gots Problem while using Exceptions (C++) 2 answers

GCC:未定义的对vtable的引用

这个问题在这里已经有了答案: g ++和gcc有什么区别? 10个答案 GCC 4.5.2链接器问题使用异常(C ++)时出现问题2个答案