Hot answers tagged

19

There have been many discussions about this. Mainly, the reason is a philosophical one. C was invented as a simple language for system development (not so much application development). There are many arguments for using C++, but there are about as many for not using C++ and sticking to C. In the end, it's a historical issue. Most application stuff is ...


16

You're right that you'll end up with the same executable at the end (albeit with a different name); in the first case gcc will actually create a bunch of temporary object files that it removes after linking, versus the second case where you're making the object files yourself. The main reason to do things the second way is to allow for incremental building. ...


12

You may want to read from cin to get a poor man’s pause – it will wait for you to type an Enter, rather than resuming while you’re getting coffee (as sleep() will).


9

The Cross compiler article on wikipedia is quite good. Generally a cross compiler is a compiler producing code for a different kind of system than yours. Usually this means a different target hardware architecture, but it can also mean a different target operating system (or both). Theoretically you could combine these and use a cross-compiler on ...


8

Every standard conforming compiler should come with STL, as it is part of the standard library. The first standard was finalized in 1998, so unless you are using a really old system, it should be available. All you need to do is use the proper #includes. #include <vector> std::vector<int> v;


8

Here is a breakdown of the command. First the original command, for reference g++ -Wall -I/usr/local/include/thrift *.cpp -lthrift -o something Now, for the breakdown. g++ This is the actual command command, g++. It is the program that is being executed. Here is what it is, from the man page: gcc - GNU project C and C++ compiler This is a ...


7

Use -mtune. -march is used to determine the allowed instruction set, whereas -mtune is to be used to tune performance of the code (as always, see man gcc). Depending on the precise CPU type, you might also consider values other than core2. And if you use a recent GCC version (at least 4.4, I think), you might best use native instead.


7

For developing C/C++ you need the gcc compiler, which is included in most Linux distributions or can be easily installed. There is not a default IDE: most people use their favorite editor (vim, emacs, Geany etc...) and there are IDEs like Eclipse or KDevelop available. C# can be done with Mono, but it is not fully compatible with .NET: check the ...


6

For external representations, UTF-8 is definitely the standard. Some 8-bit encodings are still strong (mostly in Europe) and some 16-bit encodings are still strong (mostly in East Asia), but they are clearly legacy encodings, on their slow way out. UTF-8 is standard not only on unix, but also on the web. For internal representations, there's no such ...


6

From this answer to "Install gcc 4.7 on CentOS [6.x]", the easiest way to get g++ 4.7, and the required tools and libraries, for CentOS 5.x is via the devtools package: cd /etc/yum.repos.d wget http://people.centos.org/tru/devtools/devtools.repo yum --enablerepo=testing-devtools-6 install devtoolset-1.0 Since you're running g++ manually (as opposed to ...


6

Same thing for cout/cerr, and you can just use sleep() - see man 3 sleep or man 3 usleep for more info.


6

You're leaving a zombie, trivially, because you didn't wait on your child process. Your shell is immediately exiting because you've set up its STDIN in a nonsensical way. pipe returns a one-way communications channel. You write to pipefd[1] and read it back from pipefd[0]. You did a buch of dup2 calls which lead the shell to attempt to read (STDIN) from the ...


5

On Debian derived systems you can get the source (even as a non root user) using apt-get source provided sources.list has some deb-src entries. Otherwise it's stuck with downloading from the project source repository with standard tools. Once you've got that source then: ./configure --prefix=/home/me/mysoftware make make install Will work for most source ...


5

I sometimes resort to this #define BRK() do { printf("%s %d\n", __FILE__, __LINE__); getchar(); } while (0) ... BRK(); // Stop and wait for enter Also, function instrumentation might help: GCC allows to hook into every function enter/exit, see http://stackoverflow.com/questions/2281739/automatically-adding-enter-exit-function-logs-to-a-project


5

I have also .1 as I can see from the content it is used for manual Yes, these are written in groff markup. They aren't compiled, they're interpreted at runtime via man or some other viewer (using groff as a backend). The .1 actually denotes the manual section (see man man). When an executable is installed into an element of the system's executable ...


5

The main entry point is God. Be it a C or C++ source file, it is the center of the application. Only in the same way that nitrogen is the center of a pine tree. It is where everything starts, but there's nothing about C or C++ that makes you put the "center" of your application in main(). A great many C and C++ programs are built on an event loop or an ...


5

This has more to do with C and C++ than Unix, and as such belongs to SO. To answer your question, the <> indicates headers in the standard library and "" the libraries written specifically for the project. From the K&R: Any source line of the form #include "filename" or #include <filename> is replaced by the contents ...


5

If you trust the local machine not to be spoofing, both ifconfig and ip addr will give you the MAC address of the hardware. If you don't trust the local machine, neither ethtool, ifconfig, nor ip is going to provide you the information you need. Because there are very legitimate reasons for MAC spoofing (for example, hot-fail on ethercards) all the drivers ...


5

Depends - if you actually develope kernel space drivers that use mutexes and semaphores you should give the patches a quick review. As developer that is your responsibility, no answer on a website will solve that issue. If you are mainly developing userspace software, these changes do not affect you, as you only wrangle with the kernel interfaces, which are ...


4

On a Ubuntu system, you can install the c++ compiler along with common development libraries with the build-essential package. This is a meta package that depends on the following: libc6-dev | libc-dev, gcc, g++, make, dpkg-dev This is the base of what is needed for compiling C and C++. Other development libraries can be installed as-needed.


4

Run it on a decicated computer just for these tasks or in virtual.


4

libstdc++ 3 is not the default libstdc++ anymore. You can still install it, though it is best to do so with your distro package util. I'm assuming your BOINC client is for your arch, x86_64, and not compiled for x86. The difference is significant in resolving dependency issues. Considering you are on a regular user account, you should theoretically be ...


4

It's probably killed by kernel's oom killer. dmesg should contain information about it. Sorry, but you may need to redesign your algorithm.


4

This is just a partial answer, since your question is fairly broad. C++ defines an "execution character set" (in fact, two of them, a narrow and a wide one). When your source file contains something like: char s[] = "Hello"; Then the numeric byte value of the letters in the string literal are simply looked up according to the execution encoding. (The ...


4

I guess all you need is a package providing the g++ command (plus all the dependencies, of course).


4

preamble you probably don't want to invest time into preventing people from disassembling your code: instead focus on making your project better, so that once your competitors have figured out how you did feature X, your software already has feature Y... the reasoning is simple: if you have a dull project, then nobody will care to disassemble it and you ...


4

Here the simplest analogue of lsusb: #include <stdio.h> #include <usb.h> main(){ struct usb_bus *bus; struct usb_device *dev; usb_init(); usb_find_busses(); usb_find_devices(); for (bus = usb_busses; bus; bus = bus->next) for (dev = bus->devices; dev; dev = dev->next){ printf("Trying device ...


4

read and write don't take a reference; they take a pointer. Prefix-& is the address-of operator, which returns a pointer. It's postfix-& which indicates a reference. Passing data to another program in this manner can work, but only under the following circumstances: The class does not use pointers, but stores everything inside the class itself The ...


3

Since "handle big data files" does not give much more information of what you want to do, i'm guessing some simple data processing. Bash shell scripts are generally terribly slow by themselves, but for text processing purposes might be just what you need, in combination with the cli tools such as grep, sed, awk, cut, sort, uniq, wc and others. In many ...


3

You need to use clang++. clang is the C compiler, clang++ is the C++ compiler. Like gcc. I think these are basically the same compiler under the hood, but (again like gcc), clang++ links against the C++ libraries by default, while clang doesn't. Hence the linker errors.



Only top voted, non community-wiki answers of a minimum length are eligible