[Search for users] [Overall Top Noters] [List of all Conferences] [Download this site]

Conference turris::decc

Title:DECC
Notice:General DEC C discussions
Moderator:TLE::D_SMITHNTE
Created:Fri Nov 13 1992
Last Modified:Fri Jun 06 1997
Last Successful Update:Fri Jun 06 1997
Number of topics:2212
Total number of notes:11045

2172.0. "C declaration problem" by NNTPD::"[email protected]" (Adrian Morrisson) Wed Apr 30 1997 21:29

Hi.
	I'm not overly familiar with C but I can't get an explanation as to
why the following will not work.(This is cc on DU 3.2).My customer has written

a C program. In case one he defines a char array at the end of his character 
definitions but before his enum definitions. This compiles ok but when it runs
 he gets an "exception system: exiting due to internal error: runtime function
entry or table not found"
In the second case he moved the definition to after the struct definitions and
it runs ok. He claims this is a problem with the C compiler.

I've included the definitions below. They are all global and defined before
any 
code is defined. The offending line is char holdback_array[40][MAXDATA];

The two c programs are identical and I can make them available if any one
wants 
to go deeper with them. At the moment I'd just like to see if this behaviour
is 
compiler related or programming related.


Thanks


Adrian Morrisson

Case ONE (cause exception 

#define MAXINPUT 235  /* should be 50 from spec */
#define MAXDATA MAXINPUT-5
#define HEADERBLOCK_SIZE 34
#define LINEBLOCK_SIZE 24
#define KEYLENGTH 29
#define GST 1.125

#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

int block_number=0;
int first_invoice_line=1;
int start_document=1;
int first_card=1;
int number_of_cards=1;
int previous_card_numeric=0;
int current_card_numeric=0;
int copy_invoice=0;
int stock_usage=0;
int holdback_list_last_element=0;

char input_buffer[MAXINPUT]="";
char input_line[MAXINPUT]="";
char file_header[MAXINPUT]="";
char CNUM_key[MAXINPUT-5]="";
char INUM_key[MAXINPUT-5]="";
char SDAT_key[MAXINPUT-5]="";
char LOC1_key[MAXINPUT-5]="";
char holdback_array[40][MAXDATA]; 		/* Causes exception */

double air_cardtotal_excl=0, air_cardtotal_gst=0, air_cardtotal_inc=0;
double TPIT_total=0, TINV_total=0;
double exchange_rate_numeric=0;
double Total_TPXT_value_float=0;

unsigned long total_recs_read=0, total_invoice_lines_read=0,
total_ELF_recs_written=0;
unsigned long total_cp_written=0, total_FMAT=0, self_billing_count=0;

enum {UNDEFINED, MKTG, DOMOIL, AIR, ASWIPE, ANOSWP, AUSNZ, AUSUS, MARINE,
MUSNZ, MUSUS, DUAL} FMAT;
enum key_type {CNUM, INUM, SDAT, LOC1};

struct {
          char invoice_line[MAXINPUT];
       } line_block[LINEBLOCK_SIZE][7];

FILE *ISP_data_mod, *ELF_data, *encode_log, *ISP_data;



/* this function replaces \n with \0 */
	functions down here.


CASE 2
#define MAXINPUT 235  /* should be 50 from spec */
#define MAXDATA MAXINPUT-5
#define HEADERBLOCK_SIZE 34
#define LINEBLOCK_SIZE 24
#define KEYLENGTH 29
#define GST 1.125

#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <time.h>

int block_number=0;
int first_invoice_line=1;
int start_document=1;
int first_card=1;
int number_of_cards=1;
int previous_card_numeric=0;
int current_card_numeric=0;
int copy_invoice=0;
int stock_usage=0;
int holdback_list_last_element=0;

char input_buffer[MAXINPUT]="";
char input_line[MAXINPUT]="";
char file_header[MAXINPUT]="";
char CNUM_key[MAXINPUT-5]="";
char INUM_key[MAXINPUT-5]="";
char SDAT_key[MAXINPUT-5]="";
char LOC1_key[MAXINPUT-5]="";

double air_cardtotal_excl=0, air_cardtotal_gst=0, air_cardtotal_inc=0;
double TPIT_total=0, TINV_total=0;
double exchange_rate_numeric=0;
double Total_TPXT_value_float=0;

unsigned long total_recs_read=0, total_invoice_lines_read=0,
total_ELF_recs_written=0;
unsigned long total_cp_written=0, total_FMAT=0, self_billing_count=0;

enum {UNDEFINED, MKTG, DOMOIL, AIR, ASWIPE, ANOSWP, AUSNZ, AUSUS, MARINE,
MUSNZ, MUSUS, DUAL} FMAT;
enum key_type {CNUM, INUM, SDAT, LOC1};

struct {
          char invoice_line[MAXINPUT];
       } line_block[LINEBLOCK_SIZE][7];

char holdback_array[40][MAXDATA];	/* works ok *?

FILE *ISP_data_mod, *ELF_data, *encode_log, *ISP_data;


void add_string_term(char in_string[MAXDATA])
Funtions down here
[Posted by WWW Notes gateway]
T.RTitleUserPersonal
Name
DateLines
2172.1Full SourcesXDELTA::HOFFMANSteve, OpenVMS EngineeringThu May 01 1997 09:3921
  "cc" -- without -migrate, if memory services -- isn't DEC C on DIGITAL
  UNIX, it's pcc.
  
  On zero evidence, I'd expect this was an application programming bug.
  I'd look for code in the area of the non-working holdback_array[][]
  variable that is unintentionally referencing and overwriting another
  (nearby) variable.

  I'd expect the "working" version is also broken, but the fault is latent
  and not as obvious.

  I will assume the customer has made some attempt to debug this problem.
  (These problems can sometimes be painful to find, which is why some folks
  tend to assume the fault lies elsewhere.)

  You'll likely need to post a pointer to the full source code, as these
  sorts of bugs either never show up, or show up differently, when in a
  cut-down example version.  In addition, the script used to build the
  program will be needed.

2172.2"cc -migrate" on Digital UNIX V3.2* onlyDECC::SULLIVANJeff SullivanThu May 01 1997 17:3112
> "cc" -- without -migrate, if memory services -- isn't DEC C on DIGITAL
> UNIX ...

This is correct on Digital UNIX V3.2*, however, 'cc' is DEC C on V4.0 and later.
On V4.0 and later, we recommend that you not use -migrate, since it will cause
some differences in the default flags and optimization levels. See man cc(1) for
more info.

Please try your test case again with DEC C on UNIX, if you have not does so
already.

-Jeff
2172.3ThanksNNTPD::&quot;[email protected]&quot;Adrian MorrissonMon May 05 1997 23:0413
Hi.
	Thanks for the input. I tried the -migrate switch and it didn't help. I
also tried it under Digital Unix 3.2, 4.0B with the same problem.
I've placed the source at www.stl.dec.com/~adrian/N44625 if anyone is
interested.
Test1.c barfs but supplies the correct results.
test2.c runs but doesn't supply the correct results

Thanks


Adrian
[Posted by WWW Notes gateway]
2172.4Maybe this source bug is the cause...WIBBIN::NOYCEPulling weeds, pickin&#039; stonesTue May 06 1997 10:3822
Well, this looks suspicious:

> struct {
>           char invoice_line[MAXINPUT];
>        } line_block[LINEBLOCK_SIZE][7];

> void initialise_line_block()
>{
>	int k=0;
>	int j=0;
>
>	for (k=0;k<8;k++)
>	{
>		for (j=0;j<LINEBLOCK_SIZE+1;j++)
>			strncpy(line_block[j][k].invoice_line, "", MAXINPUT);
>	}
> }

You have LINEBLOCK_SIZE arrays of 7 elements, numbered 0 thru 6, but
you are initializing 8 elements (k=0 thru k=7).  In test2, this clobbers
the holdback_array that is adjacent to it; in test1, it apparently clobbers
something that the exception system depends on.
2172.5QUARRY::nethCraig NethTue May 06 1997 10:437
The inner loop has a problem too - it will sequence up to LINEBLOCK_SIZE,
but the array only goes from 0 to LINEBLOCK_SIZE-1.  There is a similar problem
later in the program where line_block[24] is referenced, but LINEBLOCK_SIZE
is 24.

The author of the program seems to have a basic misunderstanding about how
C arrays work.
2172.6ThanksNNTPD::&quot;[email protected]&quot;Adrian MorrissonThu May 08 1997 21:0711
Hi
	Thanks very muchly,
	I've pointed out these issues with the customer (referring to 
the DEC C experts) and I'll leave it to him to fix.


Thank you


Adrian
[Posted by WWW Notes gateway]