background preloader

C

Facebook Twitter

How to declare a structure in a header that is to be used by multiple files in c. Embedding a File in an Executable, aka Hello World, Version 5967. I recently had the need to embed a file in an executable. Since I'm working at the command line with gcc, et al and not with a fancy RAD tool that makes it all happen magically it wasn't immediately obvious to me how to make this happen. A bit of searching on the net found a hack to essentially cat it onto the end of the executable and then decipher where it was based on a bunch of information I didn't want to know about.

Seemed like there ought to be a better way... And there is, it's objcopy to the rescue. objcopy converts object files or executables from one format to another. One of the formats it understands is "binary", which is basicly any file that's not in one of the other formats that it understands. Let's say we have a file name data.txt that we want to embed in our executable: # cat data.txt Hello world To convert this into an object file that we can link with our program we just use objcopy to produce a ".o" file: # gcc main.c data.o # .

A modern "C" coding guideline. Optimization of Computer Programs in C. Optimization of Computer Programs in C Michael E.

Optimization of Computer Programs in C

Lee Senior Programmer/Analyst Ontek Corporation 22941 Mill Creek Road Laguna Hills, CA 92653 USA Abstract: A substantial portion of a knowledge worker's life may be spent waiting for a computer program to produce output. Users and organizations control their wait time by purchasing faster computers, adding memory, or using faster network connections. Developers of application programs have a responsibility to design their programs make the best use of these limited and expensive resources. This document describes techniques for optimizing (improving the speed of) computer programs written in C. The single most effective optimization technique is to use a profiler to identify performance bottlenecks. Once you have identified a bottleneck, for example a loop that is executed thousands of times, remember that the best thing to do is to redesign the program so that it doesn't need to execute the loop thousands of times.

If (x ! X = 0; Old code: Vim for C Programmers. Does the job. Now comes the job of inspecting the errors, jumping to the appropriate line number in the source file and fixing them. If you want to display the line numbers in the source file, :se nu turns on this option, and :se nonu disables line number display. Once you compile, Vim automatically takes you to the first line that is causing the error. To go to the next error; use :cn to take you to the next line number causing the error.

:cfirst and :clast take you to the first error and the last error, respectively. If you want to read some other source file, say foo.c, while fixing a particular error, simply type :e foo.c. One shortcut provided by Vim to avoid typing too much to switch back to the previous file is to type :e # instead of typing the full path of the file. If you have a situation in which you have opened too many files and you want to close some of them, you can issue :ls. 2 # "newcachain.c" line 5 3 %a "cachain.c" line 1 Search and replace is a powerful tool in Vim.