Question

I have the following function. I have written it long time ago and used it well, but now it gives me a syntax error in Codevision software.... the error is in the declaration of the function and might be from the arguments....

void ReadGainPots(void);
void RxGetChannels(void);
void read_adc(uint8_t channel);
void output_motor_ppm(void);
void Initial_EEPROM_Config_Load(void);
void Save_Config_to_EEPROM(void);
void Set_EEPROM_Default_Config(void);
void eeprom_write_byte_changed( uint8_t * addr, uint8_t value );
void eeprom_write_block_changes( const char * src, void * dest, size_t size );

void eeprom_write_block_changes( const uint8_t * src, void * dest, size_t size )
{ 
size_t len;

for(len=0;len<size;len++)
{
    eeprom_write_byte_changed( dest,  *src );

    src++;
    dest++;
}
}
Était-ce utile?

La solution

Well, without the error itself, it's a little hard to diagnose :-)

The first thing I would be looking at is whether the "Codevision software" understands the uint8_t data type. This type was introduced in C99 and it wouldn't surprise me if some embedded development environments still used C90.

It could be a simple matter of including the stdint.h header. Or, if the compiler doesn't support it, you can use another, compatible data type (possibly unsigned char).

An easy way to test this is to temporarily change uint8_t to char and see if the error goes away (or possibly, moves elsewhere). If it does, then you need to figure out which is the best way to go based on whether uint8_t is valid for your implementation.

If you're certain it's supported, then show us the actual full error being generated. Without that, we're rather hamstrung.


A few more things to check.

First, it's possible that the text immediately before that declaration may be causing a problem with it. It should be checked as well.

Second (and this is likely in an environment where you mix UNIX/Windows), check the line endings. I've seen issues with Windows-based CR/LF line endings in environments where the compiler expects UNIX-based LF endings.

Comment out the function and see if the error persists elsewhere (such as in the following function). That will give a valuable clue as to the cause (in the function itself, or some environmental problem).


For what it's worth, that code itself is quite valid. The following program compiles okay:

#include <stddef.h>
#include <stdint.h>

void eeprom_write_byte_changed (void *dest, uint8_t ch ) {}

void eeprom_write_block_changes( const uint8_t * src, void * dest, size_t size )
{
size_t len;

for(len=0;len<size;len++)
{
    eeprom_write_byte_changed( dest,  *src );

    src++;
    dest++;
}
}

int main(void) {
    eeprom_write_block_changes ("hello", NULL, 42);
    return 0;
}

Autres conseils

Either change uint8_t to unsigned char

Or, try including stdint.h

or #define uint8_t yourself.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top