Moderators: simonsunnyboy, Mug UK, Zorro 2, Moderator Team
m0n0 wrote:IMO you must also declare the parameters to functions (In your case: void), I think this should do the job:Code: Select all
#include <stdio.h>
void say_hello (void);
void main () {
say_hello ();
}
void say_hello (void) {
printf ("hi\n");
}
jruark56 wrote:If I change the AES.H header file so that the OBJECT structure now refers to ob_spec as a long member, then the program compiles and links good, but crashes with two bombs on execution.
Code: Select all
TEDINFO *ob_tedinfo;
ob_tedinfo = tree_addr[NUMBERS].ob_spec.tedinfo;
jruark56 wrote:Henk/All,
I am trying to walk my way through Clayton Walnum's Cmanship Complete book, working the exercises in each chapter using AHCC as my development environment. My earlier posted questions turned out to be resolved by making a clean install in a new folder on my PC. My problem now is that the definition for an OBJECT structure is different between Clayton's book and the header files included with AHCC. The ob_spec member is defined as a long in the book, but defined as an pointer to an OBSPEC structure in AHCC.
Part of Chapter 14's program (a dialog box construction example) calls for modifying a boxed text control. The code defines a TEDINFO pointer:
TEDINFO *ob_tedinfo
A bit further down in the code ob_tedinfo needs to be set equal to tree_addr[NUMBERS] ob_spec pointer like this:
ob_tedinfo=(TEDINFO *)tree_addr[NUMBERS].ob_spec
This fails using the definition for an OBJECT structure in AHCC. The error is that the union is not allowed. OBSPEC is defined as a union structure with possible data types including a TEDINFO pointer.
If I change the AES.H header file so that the OBJECT structure now refers to ob_spec as a long member, then the program compiles and links good, but crashes with two bombs on execution.
I can't seem to figure out how to properly use the OBJECT structure under AHCC. Any ideas about where I am going wrong?
Code: Select all
char * get_tedinfo_str (OBJECT * tree, int object) {
return tree[object].ob_spec.tedinfo->te_ptext;
}
Code: Select all
/***************************************/
/* */
/* CMANSHIP LISTING 1 */
/* CHAPTER 14 */
/* DEVELOPED WITH AHCC 5.2 */
/* */
/***************************************/
#include <osbind.h>
#include <aes.h>
#include <vdi.h>
#include <string.h>
#include <stdio.h>
#include "SAMPLE.H"
#define R_TREE 0
#define FINGER 3
/* Required GEM global arrays */
int work_in[11],work_out[57],pxyarray[10];
int contrl[12],intin[128],intout[128];
int ptsin[128],ptsout[128];
/* Some globalvariables */
int handle,dum;
int dial_x,dial_y,dial_w,dial_h,num,n_x,n_y;
char number_str[13]=" 0000 ";
OBJECT *tree_addr;
OBJECT tree;
MFORM sysmouse;
char* find_str(int object,char* string);
void open_vwork(void);
void do_dialog(void);
void do_up(void);
void do_down(void);
void edit_object(void);
void print_results(OBJECT *tree);
void button_wait(void);
int main()
{
appl_init();
open_vwork();
do_dialog();
button_wait();
rsrc_free();
v_clsvwk(handle);
appl_exit();
return(0);
}
void open_vwork()
{
int i;
handle=graf_handle(&dum,&dum,&dum,&dum);
for(i=0;i<10;work_in[i++]=1);
work_in[10]=2;
v_opnvwk(work_in,&handle,work_out);
}
void do_dialog()
{
int choice;
if(!rsrc_load("SAMPLE.RSC"))
form_alert(1,"[1][SAMPLE.RSC missing!][I'll do better]");
else
{
rsrc_gaddr(R_TREE,SAMPLE,&tree_addr);
form_center(tree_addr,&dial_x,&dial_y,&dial_w,&dial_h);
objc_offset(tree_addr,NUMBERS,&n_x,&n_y);
form_dial(FMD_START,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
form_dial(FMD_GROW,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
objc_draw(tree_addr,0,2,dial_x,dial_y,dial_w,dial_h);
graf_mouse(FINGER,&sysmouse);
num=0;
do
{
choice=form_do(tree_addr,NAME);
if(choice==RADIO1) v_gtext(handle,160,20,"Radio 1 ");
if(choice==RADIO2) v_gtext(handle,160,20,"Radio 2 ");
if(choice==RADIO3) v_gtext(handle,160,20,"Radio 3 ");
if(choice==RADIO4) v_gtext(handle,160,20,"Radio 4 ");
if(choice==RADIO5) v_gtext(handle,160,20,"Radio 5 ");
if(choice==RADIO6) v_gtext(handle,160,20,"Radio 6 ");
if(choice==OPTION1) v_gtext(handle,160,20,"Option 1 ");
if(choice==OPTION2) v_gtext(handle,160,20,"Option 2 ");
if(choice==UPARROW) do_up();
if(choice==DWNARROW) do_down();
}
while(choice!=CANCEL && choice!=OK);
form_dial(FMD_SHRINK,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
form_dial(FMD_FINISH,0,0,10,10,dial_x,dial_y,dial_w,dial_h);
print_results(tree_addr);
}
}
void do_up()
{
num+=1;
if(num>9999)
{
num=0;
strcpy(number_str," 0000 ");
}
edit_object();
}
void do_down()
{
num-=1;
if(num<0) num=9999;
edit_object();
}
void edit_object()
{
TEDINFO *ob_tedinfo;
char temp_str[10];
sprintf(temp_str,"%d",num);
strcpy(&number_str[8 - strlen(temp_str)],temp_str);
strcpy(&number_str[8]," ");
ob_tedinfo=tree_addr[NUMBERS].ob_spec.tedinfo;
ob_tedinfo->te_ptext=number_str;
objc_draw(tree_addr,NUMBERS,1,n_x,n_y,96,16);
}
void print_results(OBJECT *tree)
{
char* string;
string=find_str(NAME,string);
v_gtext(handle,160,20,"Your name is: ");
v_gtext(handle,264,20,string);
string=find_str(AGE,string);
v_gtext(handle,160,36,"Your age is: ");
v_gtext(handle,264,36,string);
string=find_str(NUMBERS,string);
v_gtext(handle,160,52,"Final number value: ");
v_gtext(handle,320,52,&string[4]);
}
char* find_str(int object,char* string)
{
TEDINFO *ob_tedinfo;
ob_tedinfo=tree_addr[object].ob_spec.tedinfo;
string=ob_tedinfo->te_ptext;
return(string);
}
void button_wait()
{
evnt_button(1,1,1,&dum,&dum,&dum,&dum);
evnt_button(1,1,0,&dum,&dum,&dum,&dum);
}
jruark56 wrote:I believe the problem to be that pointer to OBJECT *tree_addr is not being assigned a proper address.
mfro wrote:P.S.: just found the book with the original example. Seems to be wrong right there already.
jfl wrote:mfro wrote:P.S.: just found the book with the original example. Seems to be wrong right there already.
I don't think it is. The original code writes 5 chars at index 8 in a 13 chars string.
Code: Select all
strcpy(&number_str[8]," ");
jruark56 wrote:Hi all,
I have run up against another issue. Seems that AHCC (at least the binaries for the 68000) does not contain an intrinsic for the float type. Chapter 20 of Cmanship Complete uses this data type in calculating the size and position for a vertical slider. Is this a know issue with AHCC, or am I again missing something?
Users browsing this forum: No registered users and 4 guests