Date: Sat, 15 Mar 1997 17:49:39 +0200 (SAT) From: Alf Stockton Reply-To: Alf Stockton To: djgpp AT delorie DOT com Subject: DJGPP and stdprn Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII The following program compiles and runs clean under Watcom 10.? but when compiled under DJGPP 2.0 with gcc bar.c gives no errors but at run time crashes with SIGSEGV. /* * bar.c - print barcode, 3-of-9, external printer interface */ #define TEST #include #include #include static void PrintBar(int, int); /* print thick or thin line or space */ static void PrinterInitialise(char *); /* initialize */ static void PrintFinished(void); /* finish */ static void BarCode(unsigned short); /* * These codes represent the 3-of-9 encoding. Note that there are exactly * three 1-bits in each code. Those are the "thick" lines/spaces. * The barcode alternates between lines and spaces - the codes below * determine the width of each line or space, not whether it's a line * or a space. */ static unsigned short Codes[] = { 0xc4, 0x00, 0x00, 0x00, 0xa8, 0x2a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x8a, 0x00, 0x85, 0x184, 0xa2, 0x34, 0x121, 0x61, 0x160, 0x31, 0x130, 0x70, 0x25, 0x124, 0x64, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x109, 0x49, 0x148, 0x19, 0x118, 0x58, 0x0d, 0x10c, 0x4c, 0x1c, 0x103, 0x43, 0x142, 0x13, 0x112, 0x52, 0x07, 0x106, 0x46, 0x16, 0x181, 0x0c1, 0x1c0, 0x91, 0x190, 0x0d0 }; static short int Resolution = 2; // horizontal settings for width of barcode static short int Depth = 4; // lines deep/height of barcode void bar(char *String) { short int i; int ReturnCode; char *s; for(i = Depth; i > 0; --i) { ReturnCode = fprintf(stdprn,"\n"); s = String; PrinterInitialise(s); BarCode(0x94); // start code while(*s) { BarCode(Codes[*s - ' ']); ++s; } BarCode(0x94); // stop code } PrintFinished(); } void BarCode(unsigned short c) { int line; // BOOL line/space unsigned short mask = 0x100; for(line = 1; mask; line = 1 - line) { PrintBar(c & mask, line); mask >>= 1; } PrintBar(0, 0); /* finish each char with a thin space */ } /* * initialize the printer as required to print string s * the ratio of thick to thin is 3:1, and there will be 3 thicks and 6 thins. * each character is terminated by a thin space. * thus, each character is 16 * res dots wide (res * 6 + 3*res * 3 + res) * each string starts and stops with a special code, so there are * strlen(s) + 2 bytes to print. */ void PrinterInitialise(char *s) { unsigned short n; n = 16 * Resolution * (strlen(s) + 2); // total # of graphic bytes fprintf(stdprn,"%c%c%c", 0x1b, 0x33, 0x10); // n/216th of an inch line feed fprintf(stdprn,"%c%c%c%c", 0x1b, 0x4c, n & 0xff, n >> 8); // 120 DPI graphics } /* * This is the place to put any other printer reset commands you want, * like 6 LPI, condensed print, or whatever. */ void PrintFinished() { fprintf(stdprn,"%c%c", 0x0d, 0x0a); // carriage return & line feed fprintf(stdprn,"%c%c",0x1b,0x30); // 1/8" line feed fprintf(stdprn,"%c%c",0x1b,0x40); // re-initialise printer } /* * print an individual line or space, thick or thin * args are boolean */ void PrintBar(int thick, int line) { short int w, c; w = Resolution * (thick ? 3 : 1); c = line ? 0xff : 0; while(w--) { fprintf(stdprn,"%c", c); } } #ifdef TEST int main(int argc, char *argv[]) { fprintf(stdprn, "987654321\n"); bar("987654321"); return(0); } #endif What have I done wrong ? I suspect that GCC knows nothing of stdprn and that Watcom, Turbo/Borland C and MicroSoft do. If GCC doesn't why don't I get a compile error ? I have not found any reference in info but maybe I haven't looked far enough. Regards, Alf Stockton stockton AT fast DOT co DOT za