quek wrote:
Im having a problem passing a struct ptr.
Maybe someone could help me.
Heres what Visual C gives me as error:
error C2664: 'adpcm_coder_u' : cannot convert parameter 4 from 'struct
main::$S1 *' to 'struct adpcm_state *'
Types pointed to are unrelated; conversion requires
reinterpret_cast, C-style cast or function-style cast
This diagnostic suggests that you are not using your compiler as a C
compiler, but as a C++ compiler.
Here is the code
Here's a commented and somewhat corrected (up to being compilable) version:
#include <stdio.h> /* mha: the variadic function printf
*must* have a declaration visible.
Including <stdio.h> is not only an
easy way to do this, but it makes
sure that the declaration is right. */
struct adpcm_state
{
short valprev; /* Previous output value */
char index; /* Index into stepsize table */
};
extern void adpcm_coder_u(unsigned char[], char[], int, struct
adpcm_state *);
extern void adpcm_decoder_u(char[], unsigned char[], int, struct
adpcm_state *);
/* mha: main returns an int. This is so fundamental and is repeated
so many times a day here, that your use of 'void' as the return
type is prima facie evidence that you did not follow the newsgroup
before posting (a usenet sin) and that you did not check the FAQ
before posting (another usenet sin). This may seem a small thing
to get worked up over, but you *cannot* make this error if you have
observed the basic etiquette of newsgroups. I've fixed the error. */
int main(void)
{
int i;
int inputArray[20];
unsigned char aLawArray[20];
char adpcmArray[20];
struct adpcm_state *state; /* mha: the 'struct *state;' which was
here does not say which of the
various types of structs state might
point to. */
for (i = 0; i < 20; i++) {
inputArray[i] = 20 * (i + 10);
}
for (i = 0; i < 20; i++) {
/* mha: there is no function 'linear2alaw' declared. */
aLawArray[i] = linear2alaw(inputArray[i]);
}
adpcm_coder_u(aLawArray, adpcmArray, 20, state);
for (i = 0; i < 20; i++) {
printf("%d Linear = %d aLaw = %d adpcm %d\n", i,
inputArray[i], aLawArray[i], adpcmArray[i]);
/* mha: I added the '\n' to your specification string. There are
two reasons for this. The first is aesthetic (20 run-together
lines are very hard to read), the second is to ensure that the
last line of output has a final end-of-line character.
Without this, the behavior is not portable. note that your
specification string was broken by your posting software.
This leads to compilation errors that you didn't even have
before. */
}
return 0; /* mha: main returns an int, you should
do so explicitly even if your
compiler (and the C99 standard) let
you get away without doing so. */
}