#!/bin/sh # This is a shar archive. # The rest of this file is a shell script which will extract: # # 2_10a.c 2_10a1.c 2_10a2.c 2_10a3.c 2_10a4.c 2_10a5.c 2_10b.c 2_10c1.c 2_10c2.c 2_10tst.c makefile # # To extract the files from this shell archive file simply # create a directory for this file, move the archive file # to it and enter the command # # sh filename # # The files will be extracted automatically. # Note: Do not use csh. # # Archive created: Mon Jul 30 22:57:35 EDT 1990 # echo x - 2_10a.c sed 's/^X//' > 2_10a.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ const one = 1; int *p1 = &one; #include void chconst() { one = 2; *p1 = 2; int *p2 = (int *) &one; int memint = 2; memcpy((void*)&one, &memint, sizeof (int)); } !EOF! ls -l 2_10a.c echo x - 2_10a1.c sed 's/^X//' > 2_10a1.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // changing the value of a constant // version 1 const one = 1; void chconst() { one = 2; } !EOF! ls -l 2_10a1.c echo x - 2_10a2.c sed 's/^X//' > 2_10a2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // changing the value of a constant // version 2 const one = 1; void chconst() { int *p = &one; *p = 2; } !EOF! ls -l 2_10a2.c echo x - 2_10a3.c sed 's/^X//' > 2_10a3.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // changing the value of a constant // version 3 const one = 1; void chconst() { int *p = (int *) &one; *p = 2; } !EOF! ls -l 2_10a3.c echo x - 2_10a4.c sed 's/^X//' > 2_10a4.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // changing the value of a constant // version 4 const one = 1; #include void chconst() { int memint = 2; memcpy((void*)&one, &memint, sizeof(int)); } !EOF! ls -l 2_10a4.c echo x - 2_10a5.c sed 's/^X//' > 2_10a5.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ // changing the value of a constant // version 5 const one = 1; #include void chconst() { int memint = 2; memcpy((char*)&one, (char*)&memint, sizeof(int)); } !EOF! ls -l 2_10a5.c echo x - 2_10b.c sed 's/^X//' > 2_10b.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ const num[] = { 1, 2 }; void chconst() { num[1] = 2; } !EOF! ls -l 2_10b.c echo x - 2_10c1.c sed 's/^X//' > 2_10c1.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ const one = 1; !EOF! ls -l 2_10c1.c echo x - 2_10c2.c sed 's/^X//' > 2_10c2.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ const num[] = { 1, 2 }; !EOF! ls -l 2_10c2.c echo x - 2_10tst.c sed 's/^X//' > 2_10tst.c << '!EOF!' /* Copyright (c) 1990 by AT&T Bell Telephone Laboratories, Incorporated. */ /* The C++ Answer Book */ /* Tony Hansen */ /* All rights reserved. */ extern void chconst(); main() { chconst(); } !EOF! ls -l 2_10tst.c echo x - makefile sed 's/^X//' > makefile << '!EOF!' CC= CC -I. -I../../CC all: 2_10a 2_10a1 2_10a2 2_10a3 2_10a4 2_10a5 2_10b 2_tst.o: 2_10tst.c $(CC) -c 2_10tst.c 2_10a: 2_10a.c 2_10tst.o $(CC) 2_10a.c 2_10tst.o -o 2_10a 2_10a1: 2_10a1.c 2_10tst.o $(CC) 2_10a1.c 2_10tst.o -o 2_10a1 2_10a2: 2_10a2.c 2_10tst.o $(CC) 2_10a2.c 2_10tst.o -o 2_10a2 2_10a3: 2_10a3.c 2_10tst.o $(CC) 2_10a3.c 2_10tst.o -o 2_10a3 2_10a4: 2_10a4.c 2_10tst.o $(CC) 2_10a4.c 2_10tst.o -o 2_10a4 2_10a5: 2_10a5.c 2_10tst.o $(CC) 2_10a5.c 2_10tst.o -o 2_10a5 2_10b: 2_10b.c 2_10tst.o $(CC) 2_10b.c 2_10tst.o -o 2_10b test: all echo tests done !EOF! ls -l makefile # The following exit is to ensure that extra garbage # after the end of the shar file will be ignored. exit 0