Tag Info

Hot answers tagged

243

Summary: The primary reason for switching from GCC to Clang is the incompatibility of GCC's GPL v3 license with the goals of the FreeBSD project. There are also political issues to do with corporate investment, as well as user base requirements. Finally, there are expected technical advantages to do with standards compliance and ease of debugging. Real world ...


61

You can't just ./fork.c (it's not a program; it's the source for a program): this assumes that the file is a script (which it isn't) and treats it accordingly. (However, as noted in another answer, there are compilers (like Tiny C Compiler) that can execute C code without explicitly compiling it) Since it's a C program, you have to compile the program. Try ...


29

One thing worth considering is that FreeBSD is currently using GCC 4.2.1 as noted in ire_and_curses answer thus the performance comparisons aren't of 4.5 or even 4.6 aren't truly relevant to the project. Therefore, the questions you should be asking are: What are the performance gains of the new Clang vs the older GCC that the project uses? How do the same ...


22

That's not a program, that's the source code for a program. C is a compiled language, meaning it must be "compiled" into machine-readable instructions before you can run it. As you are using C, the "C Compiler" (cc) can do this. cc -o fork for.c # compile the code chmod +x fork # ensure it it executable ./fork # run the compiled program ...


18

The new process will be created within the fork() call, and will start by returning from it just like the parent. The return value (which you stored in retval) from fork() will be: 0 in the child process The PID of the child in the parent process -1 in the parent if there was a failure (there is no child, naturally) Your testing code works correctly; it ...


18

mkdir --parents folder/subfolder/subsubfolder mkdir -p folder/subfolder/subsubfolder


17

System calls per se are a concept. They represent actions that processes can ask the kernel to perform. Those system calls are implemented in the kernel of the UNIX-like system. This implementation (written in C, and in asm for small parts) actually performs the action in the system. Then, processes use an interface to ask the system for the execution of ...


15

GNU/Linux systems usually use either glibc (Fedora/Redhat family, Arch) or its close cousin, eglibc (Debian/Ubuntu family); since eglibc is now being merged back into glibc (see EGLIBC 2.19 Branch Created under "News"), in the near future they will all be glibc again. The easiest way to check the exact version is to ask ldd, which ships with the C library. ...


14

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. ...


13

The standard way to log from a C program is syslog. Start by including the header file: #include <syslog.h> Then early in your program, you should configure syslog by calling openlog: openlog("programname", 0, LOG_USER); The first argument is the identification or the tag, which is automatically added at the start of each message. Put your ...


13

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 ...


12

Emacs/Vim/Eclipse/... - Personally I am an Emacs user. If you find the control sequences tire your pinky, just Viper-Mode it up. Emacs is so well integrated into unix, making it very easy to control everything all from one place. Vim also does a good job here, but I find Elisp to be a much more powerful extension language than Vim Script. One could talk ...


12

Why does a Linux distribution have gcc installed in advance? A Linux distribution is rather vague. Some install it, most offer to install it (possibly even if you select the defaults during installation). However not all distributions will install it and you usually have a choice. Is it because most of the applications in Linux are written in C? ...


12

Of course it won't crash the kernel, you're writing to the virtual memory space of your own program, not the real kernel memory space. Learn more about virtual memory here P.S: Why printf doesn't print anything? By default standard output is line-buffered, and your hello world doesn't contain a line separator. So if the program crashed, you will not ...


12

If you know the definition of the data type you want you can use getconf to find these values out on most Unix systems. $ getconf CHAR_BIT 8 The list of variables is defined in the man page man limits.h as well as here, man sysconf, in addition to being on disk. You can use locate limits.h to find it, it's often here: /usr/include/linux/limits.h.


12

Your program does exactly what you tell it to do: it changes the working directory for itself to /home/enedil/projects/algo. But once it exits, the shell's working directory is restored. I guess what you want to achieve is to change the working directory of the parent process, i.e. the shell, without resorting to a simple cd. There is a method, but as its ...


11

I thought that fork() creates a same process, so I initially that that in that program, the fork() call would be recursively called forever. I guess that new process created from fork() starts after the fork() call? Yes. Let's number the lines: int main (int argc, char **argv) { int retval; /* 1 */ ...


11

Because getc() buffers the read data before returning it, so a call to getc() does not necessarily result in a call to read(). read() is a system call, which takes much longer time to accomplish than a normal function call because the kernel has more operations to do. When you enter the kernel space, it changes your stack, saves all the context, deals with ...


10

Man pages for the standard C library are included in the man-pages package. For the C++ STL library the man-pages and HTML documentation are included in the libstdc++-docs packages. Thus, yum install man-pages libstdc++-docs should install them. You can test if they are available via: man std::iostream man fopen Kind of off-topic: IMHO the libstdc++ ...


10

A device that has the functions of a physical terminal without actually being one. Created by terminal emulators such as xterm. More detail is in the manpage pty(7). Traditionally, UNIX has a concept of a controlling terminal for a group of processes, and many I/O functions are built with terminals in mind. Pseudoterminals handle, for example, some control ...


10

In the latest versions of gcc compiler require that libraries follow the object or source files. So to compile this it should be: gcc pthread_sample.c -lpthread Normally though pthread code is compiled this way: gcc -pthread pthread_sample.c


10

There are several possibilities. One method is to compile using :!gcc file.c But a nicer strategy would be to have a Makefile and compile just using :make Where the easiest Makefile would look like. program: gcc file.c Others can explain this a lot better.


9

t_open() and its associated /dev/tcp and such are part of the TLI/XTI interface, which lost the battle for TCP/IP APIs to BSD sockets. On Linux, there is a /dev/tcp of sorts. It isn't a real file or kernel device. It's something specially provided by Bash, and it exists only for redirections. This means that even if one were to create an in-kernel /dev/tcp ...


8

$ man 2 read ... READ(2) Linux Programmer's Manual READ(2) NAME read - read from a file descriptor SYNOPSIS #include <unistd.h> ...


8

Even though GCC is GPLv3, the resulting binaries produced by GCC never had any license constraint. In clear you can use GCC to build software that falls under the license you want. Even the C library that comes with GCC and that is included in the binary is license-free. http://www.gnu.org/licenses/gcc-exception-faq.html Section 2 of the GNU GPLv3: You ...


7

The two most common suggestions you will hear are vim and emacs. Both are good programmable text-editors that are used by many developers. I am an occasional, amature programmer and an emacs user so here are some of the pros of using emacs: Syntax Highlighting Smart Code Navigation & Editing: c-mode allows you to quickly move between various sections ...


7

You can use the Glibc manual as a reference. It's not for absolute beginners, but if you're reasonably fluent in C you should be able to read a section and write a working program. You can find the source of the GNU tools on the GNU website; the easiest way to get it is to obtain the source packages on your Linux distribution (e.g. apt-get source coreutils ...


7

You could move the espeak binary to something like espeak-real, and replace it with a small script that sets LD_PRELOAD before exec'ing espeak-real. #! /bin/bash export LD_PRELOAD=/your/lib.so exec espeak-real "$@" (stdin/out/err redirections take care of themselves.)


7

The canonical way to do this in Vim is to use the compiler configuration setting. Your vim installation almost certainly comes with a compiler plugin for gcc. Type :help compiler in Vim to find out more about how this works. To associate gcc with c source files, you need something like this in your .vimrc: au BufEnter *.c compiler gcc


7

The start address is the address of main(), right? Not really: The start of a program isn't really main(). By default, GCC will produce executables whose start address corresponds to the _start symbol. You can see that by doing a objdump --disassemble Q1. Here's the output on a simple program of mine that only does return 0; in main(): 0000000000400e30 ...



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