[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[open-cobol-list] Question about assignment in translated C by OpenCOBOL
From: |
henry wang |
Subject: |
[open-cobol-list] Question about assignment in translated C by OpenCOBOL |
Date: |
Fri Nov 4 12:22:43 2005 |
Hi OpenCOBOL developers,
I´m using the functionality of OpenCOBOL: translate
COCOL program test1.cob to C, then add some API,
Today I encounter the problem of assignment in
translated C by OpenCOBOL.
--------------- test1.cob (only 9 lines)
---------------
IDENTIFICATION DIVISION.
PROGRAM-ID. test1.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 HH0006 PIC S9(0007)V PACKED-DECIMAL VALUE 128.
PROCEDURE DIVISION.
DISPLAY "HH0006 is " HH0006.
STOP RUN.
-------------------end of test.cob
--------------------------
run:
# cobc test1.cob -fmain -free -C
I get test1.c and test1.c.h
I want to change HH0006 from initial value 128 to 1,
following two lines are added in the test.c:
int new_value = 1;
(*(int *) (b_5)) = new_value;
Now I get the new value of HH0006:+0100000
Euh... it is +0100000, I wish that '+0000001' will be
displayed.
In file test.c.h ´static unsigned char b_5[4];´ is
generated for variable HH0006.
Could you help me for the correct assignment? Thank
you in advance!
Kind regards,
Henry
-------------- test1.c ----------------
/* Generated from test1.cob by cobc version 0.33 patch
level 0 */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <libcob.h>
#define COB_SOURCE_FILE "test1.cob"
#define COB_PACKAGE_VERSION "0.33"
#define COB_PATCH_LEVEL 0
/* function prototypes */
static int cob_get_numdisp (unsigned char *data, int
size);
static int test1_ (int);
static int
cob_get_numdisp (unsigned char *data, int size)
{
int retval = 0;
if ( size > 0 ) {
while ( size-- ) {
retval *= 10;
retval += (*data - '0');
data++;;
}
}
return retval;
}
int test1 (void);
int
main (int argc, char **argv)
{
cob_init (argc, argv);
cob_stop_run ( test1() );
}
/* functions */
int
test1 ()
{
return test1_ (0);
}
static int
test1_ (int entry)
{
static int initialized = 0;
static cob_module module = { NULL, NULL, 0, '.',
'$', ',', 0, 1, 1, 0, 0};
#include "test1.c.h"
/* perform frame stack */
int frame_index;
struct frame { int perform_through; void
*return_address; } frame_stack[254];
/* Start of function code */
module.next = cob_current_module;
cob_current_module = &module;
if ( __builtin_expect(!initialized, 0) )
{
if (!cob_initialized) {
fputs("cob_init() has not been called\n",
stderr);
cob_stop_run (1);
}
cob_check_version (COB_SOURCE_FILE,
COB_PACKAGE_VERSION, COB_PATCH_LEVEL);
initialized = 1;
}
(*(int *) (b_2)) = 0;
(*(int *) (b_3)) = 0;
cob_move (&c_8, &f_5);
/* initialize frame stack */
frame_index = -1;
frame_stack[0].perform_through = -1;
/* initialize number of call params */
(*(int *) (b_3)) = cob_call_params;
goto l_6;
/* PROCEDURE DIVISION */
/* test1: */
l_6:;
/* test1.cob:7: DISPLAY */
{
cob_display (&c_11);
cob_display (&f_5);
cob_newline ();
}
//------------ lin8 98~107 are added by me
---------------------
printf ("In file test.c.h ´static unsigned char
b_5[4];´ is generated for variable HH0006\n");
int new_value = 1;
(*(int *) (b_5)) = new_value;
printf ("I want to change HH0006 from initial value
128 to 1, following two lines are added in the
test.c:\nint new_value = 1;\n(*(int *) (b_5)) =
new_value;\n");
printf ("Now I get the new value of HH0006:");
cob_display (&f_5);
cob_newline ();
printf ("Euh... it is +0100000, I wish that
'+0000001' will be displayed.\n");
printf ("Could you help me for the correct
assignment? Thank you in advance!\n");
/* test1.cob:8: STOP */
{
cob_stop_run ((*(int *) (b_2)));
}
cob_current_module = cob_current_module->next;
return (*(int *) (b_2));
}
------------- end of test1.c ------------
--------------- test1.c.h ----------------
/* Generated from test1.cob by cobc version 0.33 patch
level 0 */
static unsigned char b_2[4]; /* RETURN-CODE */
static unsigned char b_3[4]; /*
NUMBER-OF-CALL-PARAMETERS */
static unsigned char b_5[4]; /* HH0006 */
static cob_field_attr a_10 = {33, 0, 0, 0, 0};
static cob_field_attr a_9 = {18, 7, 0, 1, 0};
static cob_field_attr a_7 = {16, 3, 0, 0, 0};
static cob_field f_5 = {4, b_5, &a_9}; /* HH0006 */
static cob_field c_11 = {10, (unsigned char *)"HH0006
is ", &a_10};
static cob_field c_8 = {3, (unsigned char *)"128",
&a_7};
------------------- end of test1.c.h -----------
__________________________________
Start your day with Yahoo! - Make it your home page!
http://www.yahoo.com/r/hs
- [open-cobol-list] Question about assignment in translated C by OpenCOBOL,
henry wang <=