Thursday, August 9, 2007

multiple definition error, cpp

Say you have *.h file with header guards (see below):

#ifndef SOME_HEADER_
#define SOME_HEADER_

int a; //it leads to multiple definition error, because the header guards protect
//multiple inclusion of a header file in a single translation unit
//if you include this file in several translation units then the error
//will occur
//To prevent this, you should move the definition in some implementation file
//or make it inline/static

#endif /*SOME_HEADER_*/

And another one thing on header guards:
//__SOME_HEADER_ - WRONG: two leading underscores, implementation reserved
// _SOME_HEADER_ - WRONG: one leading underscore, implementation reserved
// SOME_HEADER_ - RIGHT:

Wednesday, July 4, 2007

Interesting books to read #1

Technical
  • Secrets of the C++ Masters by Jeff Alger
  • C++ for Real Programmers by Jeff Alger
  • Design Patterns: Elements of Reusable Object-Oriented Software by Erich Gamma et al


Linguistics
  • Corpora in Applied Linguistics by Susan Hanston


Other
  • How to write a thesis by Rowena Murray - excellent book,  must read

Saturday, June 9, 2007

Makefile for multiple binaries

CC = gcc.exe
BIN = test01.exe \
test02.exe \
test03.exe

OBJ = $(BIN:.exe=.o)
CXXFLAGS = -lstdcxx -lm
RM = del

compile: $(BIN)

$(BIN): %.exe : %.o
$(CC) $< -o $@ $(CXXFLAGS)

$(OBJ): %.o : %.cpp
$(CC) -o $@ -c $< $(CXXFLAGS)

clean:
del *.exe del *.o