Help... pretty please...:)
I know multidimensional arrays in C++ are both possible and unusual,
particularly where they are character arrays. Non-the-less, for some things
in string work, I really think I need them and further, need them for use in
functions. I have the whole routines worked out in main, but moving the cold
block to a function blows up during the call...
// I have a problem with WATCOM C++ in learning to use it with
// multi-dimensional arrays of characters..... :(
// The problem arises out of trying to shift from string oriented BASIC
// code to C++ which is not at all a string oriented platform... :(
// Consider the problem below...
//Include files here...
// *******************************************************
// Declarations:
// ..... many other declarations are in here as well...
// Declare an array of characters which will always consume
// most of the space needed and will exist for the entire run
// time of the executable. Not only will they exist, but
// if changed, several threads in the executable may need
// concurrent access to the data in each member of the array.
// Most system level programming does not use this technique
// but in this case several instances of it for common string
// control elements in executables was well served by two-level
// string arrays in Basic as declared by K$(101), where K$(x)
// carried near-full data at all times.
// In the simplest form... I have many instances where I absolutely
// must have string arrays. Some could potentially be the subject
// of Illife vectored techniques and malloc operations. Many
// will not work at all well with these techniques. The array
// space, being near full all the time, with multiple uses in
// multiple threads needing access to the data, does not lend itself
// so I think, to Illife vectored ragged character table solutions,
// I've tried the below, structs of structs, class objects with
// public declarations and this as an element of the class,
// and calling the class to pass all the public members of it
// during run time, all with the same general error found.
static char k_[101][256]; // 101 elements of 256 character bytes
// Other declarations are possible such as:
// char (*k_)[256];
// At compile time the compiler will reduce this to the above anyway
// as the formal parameter
// char **k_; is also proper and does not change.
// the use of static insured global access...
// *******************************************************
// Function preprocessing:
// We can do a preprocessor function definition:
int pk50850(int fl[21], int k8, int k9, int n9, int o8, int o9,
char *x2_, char *w_, char *jy_, char *q_, char *q6_,
int kz[21], int ky[13], char *(*k_)[256], int gbw, char *lob_); //
READPAK:
// That might also be written as:
//int pk50850(int fl[21], int k8, int k9, int n9, int o8, int o9,
// char *x2_, char *w_, char *jy_, char *q_, char *q6_,
// int kz[21], int ky[13], char *k[101][256], int gbw, char *lob_); //
READPAK:
// That might also be written as:
//int pk50850(int fl[], int k8, int k9, int n9, int o8, int o9,
// char *x2_, char *w_, char *jy_, char *q_, char *q6_,
// int kz[], int ky[], char *k[][256], int gbw, char *lob_); //
READPAK:
// *******************************************************
// Function section:
// The applicable function might be set up as:
int pk50850(int fl[], int k8, int k9, int n9, int o8, int o9,
char *x2_, char *w_, char *jy_, char *q_, char *q6_,
int kz[], int ky[], char *k_[101][256], int gbw, char *lob_) // READPAK:
// If written this way a sample line of the function code might
// be written where the nxth element of ky :
strcpy(k_[nz][256], ""); // Set this string to null
// The function compiles. Further, if included in MAIN, the entire
// code in the function works perfectly, producing the desired results.
// If the whole program is changed to a class with public and the equivalent
// function code lines are changed to match it, if in MAIN, the results
// are the same.. It works.
// *******************************************************
// now in MAIN we attempt to call the function:
pk50850(*fl, k8, k9, n9, o8, o9,
*x2_, *w_, *jy_, *q_, *q6_,
*kz, *ky, *(k_[101])[256], gbw, *lob_); // READPAK:
// ^^ Fails compilation here
// The compiler refused to compile any form of the call I
// can think of to write. Of the above it says must be a
// pointer to character...
// No combination of:
// **k_, *k_[][256]. *(*k_)[256], *(k_[])[256]
// will compile
// Either the error refers to the fact that the call does not
// match the parameters previously defined in the function, or
// must be a pointer to character...
// Irrespective of whether we start out with:
// k_[101][256]
// **k_[]
// class pac
// public:
// etc...
// The compile run always seems to fail in the same general mode at
// call function time in MAIN...
// Peter Van Der Linden, in "Expert C Programming", beginning in
// Chapter 9 , page 239 and on for many pages, assures that it
// will work. Although the decision must be made about wasted
// space for non-Illife vectored arrays and Illife vectored arrays
// must be made by the programmer, if you declare:
// char squash[i][j]
// properly and use it properly, knowing in advance in what form
// the result returns... all is well with multi-dimensional squash.
// Yeah......
// Suggestions?
Mike @ 117/3001
--- Opus-CBCS 1.73a
---------------
* Origin: Ziplog Public Port (1:117/3001.0)
|