#include <stdio.h> #include <stdlib.h> int main(){ FILE *f,*o;char *fd;char fdd;int c; char cmd[128];fd=&fdd;char fp[30]="rp.c";char fc[30]="rc.c"; o=fopen(fc,"rb"); if(o != NULL){fclose(o);return (-1);} f=fopen(fp,"rb");o=fopen(fc,"wb"); while(fread(fd,1,1,f)){fwrite(fd,1,1,o);} fclose(o);fclose(f);return (system("gcc rc.c -o rc")); }
MAKE me!, again.
at
12/19/2009 01:02:00 PM
0
comments
Labels: C, debug, make, programming
Make me wonder
This is how I changed the make file to get what I want. I want the objects that are linked to the main program to be recompiled when a change is made in the headers. I also wanted to have a quick command to allow the use of gdb or kdb. For the sake of some education, the names with = are substituted when the name is encountered preceded by $ and enclosed in () like $(NAME). It substitutes all of the text, except the line continuation mark '\' , before it executes the make action. In this case 'DEBUGIT = -g' and '$(DEBUGIT)' would be replaced with just the two characters '-g' . One odd thing about make files, is that there MUST be a tab on the line after a line using ':' Obviously or not, the lines with # are comment lines and are ignored by make.
LIBS = -lGL -lglut -lSDL_mixer PROJECT = puzzler CC = gcc -Wall -W -ansi -pedantic # This is the flag to add to get debug symbols for GDB # See man gcc with search '/-g ' with the space! # That is vi command '/' = search # This will make the code slow usually and -O can be used DEBUGIT = -g OBJECTS = $(PROJECT)_gl.o $(PROJECT)_game.o $(PROJECT)_sdl.o $(PROJECT)_textures.o \ $(PROJECT)_save.o $(PROJECT)_matrix.o $(PROJECT)_menu.o SOURCES = $(PROJECT)_gl.c $(PROJECT)_game.c $(PROJECT)_sdl.c $(PROJECT)_textures.c \ $(PROJECT)_save.c $(PROJECT)_matrix.c $(PROJECT)_menu.c #Build is dependent on changes to makefile also DEPENDS = makefile $(PROJECT).h $(PROJECT).c $(PROJECT)_game.c \ $(PROJECT)_sdl.c $(PROJECT)_save.c $(PROJECT)_gl.c $(PROJECT)_textures.c \ $(PROJECT)_matrix.c $(PROJECT)_menu.c $(PROJECT)_game.h $(OBJECTS) puzzler: $(DEPENDS) $(CC) -c $(SOURCES) $(CC) $(PROJECT).c -o $(PROJECT) $(OBJECTS) $(LIBS) # strip $(PROJECT) # ls -la $(PROJECT) #Create the debug version, if needed puzzlerD: $(CC) $(DEBUGIT) -c $(SOURCES) $(CC) $(DEBUGIT) $(PROJECT).c -o $(PROJECT) $(OBJECTS) $(LIBS)
at
12/10/2009 09:12:00 PM
0
comments
Labels: C, games, graphics, make, programming
I forgot to remember how easy it is
I forgot how easy it was to use autoconf tools and it took about 3 minutes and a trip to my local ZIM wiki to remember what I had done before. It is as simple as this and it creates all the make files and does all the heavy lifting. autodoc is about as easy, I just have some aversion because I have not applied it to several distributions yet and I am not totally comfortable with it. It has a 600 page pdf, but I didn't read all of that. I suppose I will muddle through and apply it here and shine it up as I go. I am not even sure if I am doing it right, but I get an executable out of it and it runs, so what can I complain about.
I have started the 6 dimensional matrix that goes with the game and I think I will do something backward. Instead of making the puzzles harder, I will allow the user to apply the matrix to help solve puzzles. It is odd and could be viewed as separate 2D views and perhaps that is what I will do. Have a button that rotates the visualization through the association of the other 5 dimensions.
COMMANDS: autoreconf --install ./configure make make distcheck #CREATES DISTRIBUTION tar.gz ------------ FILES THAT NEED TO BE CREATED: ------------ Makefile.am ( in ./src ) ------------------------ bin_PROGRAMS = puzzler puzzler_SOURCES = puzzler.c puzzler.h puzzler_LDFLAGS = -lglut -lGL -lGLU -lSDL_mixer ---------------------- Makefile.am ( in ./ ) ---------------------- SUBDIRS = src dist_doc_DATA = README ------------ configure.ac ------------ AC_INIT([ampuzzler], [0.1], [bug-automake@gnu.org]) AM_INIT_AUTOMAKE([-Wall -Werror foreign]) AC_PROG_CC AC_CONFIG_HEADERS([config.h]) AC_CONFIG_FILES([ Makefile src/Makefile ]) AC_OUTPUT
The rest of the Makefiles and related files are all created by the "autoreconf --install", "./configure", and "make". and here is output from "tree". As can be seen here I have started coding the matrix and will put that up on Google code when it is done.
Mon Dec 07 02:23 PM$ tree . |-- Makefile |-- Makefile.am |-- Makefile.in |-- README |-- aclocal.m4 |-- autom4te.cache | |-- output.0 | |-- output.1 | |-- requests | |-- traces.0 | `-- traces.1 |-- config.h |-- config.h.in |-- config.log |-- config.status |-- configure |-- configure.ac |-- depcomp |-- install-sh |-- makefile.am |-- missing |-- src | |-- Makefile | |-- Makefile.am | |-- Makefile.in | |-- puzzler | |-- puzzler.c | |-- puzzler.h | |-- puzzler_game.c | |-- puzzler_game.h | |-- puzzler_gl.c | |-- puzzler_matrix.c | |-- puzzler_save.c | |-- puzzler_sdl.c | |-- puzzler_textures.c | |-- res | | |-- applause.wav | | |-- click.wav <SNIP> | | `-- won2.ogg `-- stamp-h1 3 directories, 95 files Mon Dec 07 02:45 PM$
at
12/07/2009 02:28:00 PM
0
comments
Labels: autotools, C, make, programming
More on the game einstein
I have been wandering about the "einstein" code for some time, in the same way that I play the game in my off times. I ran into this, which is more than questionable and accounts for odd behavior of some programs. I am not really sure what g++ did with this, but I am guessing that ".h" did not get recompiled like a person would think. It makes for odd stuff and life is strange enough, without adding complexity.
public:
int add(const std::wstring &name, int scores);
void save();
ScoresList& getScores();
int getMaxScore();
bool isFull();
// bool isFull() { return scores.size() >= MAX_SCORES; };
The line which is commented out is executable code and here is what happens in the assembled code. The quote below about GCC is for the sake of reference if you want more information in your assembly file.
Artur Krzysztof Szostak writes: > Is there a way to make GCC output the source code comments or corresponding > c++ source code that generated a set of assembler instructions in the .s > files? Yes. -Wa,-adhls Andrew.
This is the code generated. I did a diff with grep -v to remove some stuff and it got me the stuff I wanted to look at. I have gotten tired of looking for what really happened and have accepted that there are certain things that a person shouldn't normally do and putting real functions in in a header file is one of those things to avoid.
.LCFI108: movq %rdi, -8(%rbp) movq -8(%rbp), %rdi call _ZNKSt4listIN9TopScores5EntryESaIS1_EE4sizeEv cmpq $14, %rax seta %al movzbl %al, %eax
I suppose all of this looks like gibberish to most people. But, I speak gibber fluently :)