Down to 2 Compile Errors - Help

Go To Last Post
12 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I'm down to these two compile errors and can't for life of me figure out what is causing them:

../UART.c:23: error: expected ')' before numeric constant
../UART.c:26: error: expected ')' before numeric constant

Here is my code that is causing the error (at least this is what the compiler is pointing to for now). The errors are pointing to the function prototype and the first line (void...) of the actual function respectively.

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[]);

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[])
{
for(uint8_t i = 0; i < j; i--)
{
UDR = str_ASCII[i]; //Load TX buffer with indexed string data (i)
while(bit_is_clear(USR, UDRE)) {} //Wait for TX buffer to empty
}
}

Any ideas? Thanks

Clint

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Use the "Code" button instead of coloring your code.

Change the array type to pointer types, like so:

void SEND_STRING(uint8_t maxPeriod, char *str_ASCII);

void SEND_STRING(uint8_t maxPeriod, char *str_ASCII)
{
    for(uint8_t i = 0; i < j; i--)
    {
        UDR = str_ASCII[i]; //Load TX buffer with indexed string data (i)
        while(bit_is_clear(USR, UDRE)) {} //Wait for TX buffer to empty
    }
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Microcas wrote:
Ok, I'm down to these two compile errors and can't for life of me figure out what is causing them:

../UART.c:23: error: expected ')' before numeric constant
../UART.c:26: error: expected ')' before numeric constant

Here is my code that is causing the error (at least this is what the compiler is pointing to for now). The errors are pointing to the function prototype and the first line (void...) of the actual function respectively.

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[]);

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[])
{
for(uint8_t i = 0; i < j; i--)
{
UDR = str_ASCII[i]; //Load TX buffer with indexed string data (i)
while(bit_is_clear(USR, UDRE)) {} //Wait for TX buffer to empty
}
}

If all else fails, look at the .i file.
Use "code" instead of "color=green".
I don't know why anyone would object to the "[]"'s.
I prefer them when the parameter is supposed to point to an array.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
#include 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

> If all else fails, look at the .i file.

I also think this will be the key to the solution. One of the
identifiers there (either maxPeriod or str_ASCII) must have been
#defined to a numeric constant.

Jörg Wunsch

Please don't send me PMs, use email if you want to approach me personally.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Sorry for the color - will use the "Code" button from now on.

#define P1       PIND2
#define P0       PIND3
#define FREQ_ADJ PIND0
#define RECALC   PIND1
#define T_ADJ    10
#define MAX_HEX2ASCII	4  //Used in str_ASCII[MAX_HEX2ASCII])
#define j        MAX_HEX2ASCII

Neither maxPeriod or str_ASCII are #defined as constants. I tried changing str_ASCII[] to *str_ASCII and this didn't work either. What is the .i file? You mean the include file? Here is a list of my includes:

#include 
#include 
#include 
#include 
#include 
#include "HEX2ASCII.c"
#include "UART.c" 

Thanks for all of your help!

Clint

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Nope the .i file is the .c file after it has been passed through the C pre-processor but before it is passed to the compiler. It shows the result after all the #define'd macros have been expanded.

The easiest way to generate one (even if you use Studio) is to temporarily use Mfile (on the Start menu group of WinAVR) to create a Makefile for the project, save that to the project directory then in a command prompt switch to that directory and for the file.c in question just give the command "make file.i". This will run the pre-processor over the .c file and generate the .i

Depending on the editor you use you may now want to run it through a "unix2dos" type translator to get the \n line ends changed to \r\n's

Cliff

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok... I found the problem (at least with those two compile errors). Stupid mistake, but anyway, here is the problem:

#define uint8_t CLK_4M_BD_192K 12

The #define above was preceeding this code:

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[]);

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[])
{
  for(uint8_t i = 0; i < j; i--)
  {
    UDR = str_ASCII[i];  //Load TX buffer with indexed string data (i)
    while(bit_is_clear(USR, UDRE)) {}  //Wait for TX buffer to empty
  }
}

Causing the compiler to think uint8_t was a constant. Anyway, I fixed the #define to:

#define CLK_4M_BD_192K 12

Recompiled, found some more errors, fixed those, and now it's on to simulation. Woo hoo!

Clint

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

:shock:

Microcas wrote:

#define j        MAX_HEX2ASCII
. . . 
  for(uint8_t i = 0; i < j; i--)

EEEeeeewww! :evil: Blech! Blech!

May I humbly recommend that you never define a single-character "variable" as a constant? Instead, the following reads much easier:

  for(uint8_t i = 0; i < MAX_HEX2ASCII; i--)

See, the code is, in a way, self-documenting. You're also not going to send the next poor barstid off looking for the definition of j.

Stu (still shuddering)

Engineering seems to boil down to: Cheap. Fast. Good. Choose two. Sometimes choose only one.

Newbie? Be sure to read the thread Newbie? Start here!

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes - good point. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Nope the .i file is the .c file after it has been passed through the C pre-processor but before it is passed to the compiler. It shows the result after all the #define'd macros have been expanded.

The easiest way to generate one (even if you use Studio) is to temporarily use Mfile (on the Start menu group of WinAVR) to create a Makefile for the project, save that to the project directory then in a command prompt switch to that directory and for the file.c in question just give the command "make file.i". This will run the pre-processor over the .c file and generate the .i

I generally use the -save-temps flag.

Iluvatar is the better part of Valar.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Microcas wrote:

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[]);

void SEND_STRING(uint8_t maxPeriod, char str_ASCII[])
{
  for(uint8_t i = 0; i < j; i--)
  {
    UDR = str_ASCII[i];  //Load TX buffer with indexed string data (i)
    while(bit_is_clear(USR, UDRE)) {}  //Wait for TX buffer to empty
  }
}


Clint,
just for the record:

UDR = str_ASCII[i];

forces the compiler to calculate at the runtime the next address. It depends on the optimizer, and the size of an array element if this done by a multiplication, an add-operation or an increment. Look to the assembler listing how this is compiled. A pointer version like:

void SEND_STRING(uint8_t maxPeriod, char * pstr_ASCII)
{
  for(uint8_t i = 0; i < j; i--,pstr_ASCII++ )
  {
    UDR = *pstr_ASCII; 
...

might produce faster / smaller code.