I have this issue with one of my functions in this C++ program I'm porting over from HP-UX to LINUX. Basically, what seems to be the problem is that for the function
const char * Dictionary::lookup(const DictionaryKey &, ...)
the gcc compiler appears to be complaining that I cannot pass objects of type const Dictionary through ...
The source code for the program is pretty old and looks to utilize a lot of C-style constructs. This particular function accepts a variable list of arguments as allowed through the stdarg.h header. In addition, the warning is only reported in gcc (version 2.95.2) for HP-UX and not in LINUX's gcc (version 4.3.2).
$ gcc -lstdc++ foo1.cc foo2.cc
foo1.cc: In method `const char * Dictionary::lookup(const DictionaryKey &, ...)':
foo1.cc:178: warning: cannot pass objects of type `const DictionaryKey' through `...'
The source code for the function is available below:
const char *Dictionary::lookup (const DictionaryKey& key, ...)
{
static char res[MAX_LINE];
char *param[9];
va_list ap;
WordDictionary::iterator entry = dictionary.find (key);
if (entry != dictionary.end())
{
int idx = 1;
va_start (ap, key);
while ((param[idx] = va_arg (ap, char *)) != NULL) idx++;
va_end (ap);
char *ts = (*entry).second.textdata;
char *ts2 = res;
while (*ts)
{
if (*ts == '$')
{
ts++;
idx = *ts - '0';
strcpy (ts2, param[idx]);
ts2 += strlen(param[idx]);
ts++;
} else
{
*ts2++ = *ts++;
}
}
*ts2++ = 0;
return res;
}
else
{
return key.keydata; // Not found in dictionary
}
}
I was wondering if there was a way to repair this issue. I don't understand what is causing this warning to appear. From what I found on other websites, it appears that this warning may cause the compiled program to behave unexpectedly. Some people are saying that this should really be an error rather than a warning. I haven't had much luck determining the cause of this problem.