From 43fe9c7cdf694a80ca07f41e1372d4e51f1ba9a4 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 28 Sep 2012 06:15:04 -0700 Subject: [PATCH] Convert package from C++ to C. --- Makefile | 9 +++++++-- hello_world.cpp => hello_world.c | 8 +++----- 2 files changed, 10 insertions(+), 7 deletions(-) rename hello_world.cpp => hello_world.c (86%) diff --git a/Makefile b/Makefile index b28804a..022ef26 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ RELEASE = $(COURSE)-$(PACKAGE)-$(VERSION) PROGRAM = hello_world # Define the source files that will be distributed in the tarball -SOURCE = *.cpp COPYING Makefile README +SOURCE = *.c COPYING Makefile README # Define a list of object files needed to link PROGRAM OBJECTS = $(PROGRAM).o @@ -72,7 +72,7 @@ dist: # target: hello_world - compile the hello_world program # Use GCC to link the program from object files. $(PROGRAM): $(OBJECTS) - $(CXX) $(LDFLAGS) -o $@ $^ $(LIBS) + $(CC) $(LDFLAGS) -o $@ $^ $(LIBS) # target: run - use the program for its intended purpose # Here we just execute PROGRAM, but you could also use something like @@ -97,3 +97,8 @@ run: $(PROGRAM) # $ make CXX=/usr/local/bin/g++ CXXFLAGS=-Wall %.o: %.cpp $(CXX) $(CXXFLAGS) -c $< + +# Matching rule for compiling object files from C source +# The comments from the C++ rule above also apply here +%.o: %.c + $(CC) $(CFLAGS) -c $< diff --git a/hello_world.cpp b/hello_world.c similarity index 86% rename from hello_world.cpp rename to hello_world.c index b470249..c242304 100644 --- a/hello_world.cpp +++ b/hello_world.c @@ -1,5 +1,5 @@ /* -A simple "hello world" example in C++. +A simple "hello world" example in C. Copyright (C) 2012 W. Trevor King @@ -17,11 +17,9 @@ You should have received a copy of the GNU General Public License along with this program. If not, see . */ -#include - -using namespace std; +#include int main() { - cout << "hello, world\n"; + printf("hello, world\n"); return 0; } -- 2.26.2