Mail Archives: djgpp/1996/09/29/05:42:18
From: | cosc19z5 AT Bayou DOT UH DOT EDU (Spasmo)
|
Newsgroups: | comp.os.msdos.djgpp
|
Subject: | Problem with Some Objective-C Code
|
Date: | 29 Sep 1996 08:07:27 GMT
|
Organization: | University of Houston
|
Lines: | 102
|
Message-ID: | <52lanv$d3e@Masala.CC.UH.EDU>
|
NNTP-Posting-Host: | bayou.uh.edu
|
To: | djgpp AT delorie DOT com
|
DJ-Gateway: | from newsgroup comp.os.msdos.djgpp
|
Hey all.
I downloaded and set up djgpp so I could do some Objective C
programming (or rather learning), yet after downloading
some sample code from a web site and compiling it, the
program crashed when I tried to run it. I got an error
about a floating point exception with a trace back, but
there was no numerical manipulation in the code! It was
a hello world program!!! Anyway when I ran it via go32-v2,
ran and THEN crashed.
Anyway here's the code (directly off a web site so credits
to those). If anyone knows if the code is at fault or
if I need to goof with some settings, by all means tell me.
Thanks in advance.
Code follows:
PRINTER
_________________________________________________________________
Presented below is a simple program written in Objective-C.
The compile command for this program(using the GNU compiler) would be:
gcc -lobjc main.m printer.m -o test
(BTW, the -lobjc shouldn't be at the front)
_________________________________________________________________
MAIN.M
// This will create a Printer object, set it's string and tell it to print
#import "Printer.h"
void main()
{
id printer = [[Printer alloc] init];
[printer addStringValue:"Hello World!"];
[printer print];
[printer free];
}
PRINTER.H
#import <objc/Object.h>
@interface Printer : Object
{
char buffer[100];
}
- init;
- addStringValue:(const char*)astring;
- print;
- clear;
@end
PRINTER.M
#import "Printer.h"
@implementation Printer
- init
{
[super init];
[self clear];
return self;
}
- addStringValue:(const char*)astring
{
strcat(buffer, astring);
return self;
}
- print
{
printf("%s\n",buffer);
[self clear];
return self;
}
- clear
{
strcpy(buffer, "");
return self;
}
@end
- Raw text -