Author Topic: Please help with this C syntax error  (Read 5438 times)

0 Members and 5 Guests are viewing this topic.

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2997
  • Country: br
    • CADT Homepage
Re: Please help with this C syntax error
« Reply #25 on: June 08, 2025, 07:39:28 am »
Some embedded development environments support inclusion of data files at link time. I remember using that method with IAR EWArm to include HTML files, javascripts, images and style sheets of a web server. One gives to the linker the file path, a label to reference the base address in the C sources and a section id.

Regards, Dieter
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 5983
  • Country: gb
  • Doing electronics since the 1960s...
Re: Please help with this C syntax error
« Reply #26 on: June 11, 2025, 06:05:34 am »
Here is another mystery syntax error



SGBOOL is uint8_t
SGUINT is uint16_t
GCONSTP is const

GPALETTE_RGB is
typedef struct _GPALETTE_RGB
   {
   SGUCHAR r;
   SGUCHAR g;
   SGUCHAR b;
   } GPALETTE_RGB;

PFCODE is
  /* Memory type qualifier used for pointer to fixed data (if GCODE var * is not enough) */
  #define PFCODE   /* nothing */
« Last Edit: June 11, 2025, 06:12:07 am by peter-h »
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline radiolistener

  • Super Contributor
  • ***
  • Posts: 5733
  • Country: Earth
Re: Please help with this C syntax error
« Reply #27 on: June 11, 2025, 06:39:06 am »
try to use typedef instead of preprocessor #defines
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 5983
  • Country: gb
  • Doing electronics since the 1960s...
Re: Please help with this C syntax error
« Reply #28 on: June 11, 2025, 07:09:44 am »
The #defines for e.g. uint8_t are everywhere in this bit of code (not mine). The problem is elsewhere and may be in the typedef'd struct.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Online paulca

  • Super Contributor
  • ***
  • Posts: 6370
  • Country: gb
Re: Please help with this C syntax error
« Reply #29 on: June 11, 2025, 11:00:21 am »
In Uni when it came to C and C++ we were forbidden to do many things.

One of them was to use contractions.  The reason being,

for( ; AMACRO++; AMACRO<limit )

Becomes a completely random bit of code once the preprocessing has finished with it.  It might, if you are lucky produce a compile error.  If you are unlucky it will do something that appears valid, most of the time.

Using
for( ; AMACRO=AMACRO+1; AMACRO<limit )

Will catch more cases of inappropriate use of AMACRO than the former will.  You are first ensuring the AMACRO can "store" a result in the first place.  If it's a function call wrapper, then ++ will either post increment a register that will immediately be discarded or it will bomb out with a wicked compiler error.


MACRO_DEFINED_FUNCTION( parameters ) -1U

Is this asking for trouble? and relying exclusively on how that MACRO is implemented and if it was ever intended to be used that way.

In C++ it gets worse when operators can be macro'd!

The way to debug these things is unfortunately to add the "keep preprocessing output" flag and go and look at what ACTUALLY got compiled.

I don't know if it solves your problem, but just a "word from the wise", (my uni, not me).
"What could possibly go wrong?"
Current Open Projects:  68000 Self Build computer + OS.
 

Online peter-hTopic starter

  • Super Contributor
  • ***
  • Posts: 5983
  • Country: gb
  • Doing electronics since the 1960s...
Re: Please help with this C syntax error
« Reply #30 on: June 11, 2025, 11:06:04 am »
I am also surprised you can have a #define of nothing.
Z80 Z180 Z280 Z8 S8 8031 8051 H8/300 H8/500 80x86 90S1200 32F417
 

Offline dietert1

  • Super Contributor
  • ***
  • Posts: 2997
  • Country: br
    • CADT Homepage
Re: Please help with this C syntax error
« Reply #31 on: June 11, 2025, 01:46:31 pm »
This may be a missing bracket above within the same source file. I mean the function doesn't have a certain syntax error but a function wasn't expected..
 

Online ejeffrey

  • Super Contributor
  • ***
  • Posts: 4833
  • Country: us
Re: Please help with this C syntax error
« Reply #32 on: June 13, 2025, 01:10:08 am »
I am also surprised you can have a #define of nothing.

You probably aren't if you think about it.  It's extremely common.  It's mostly used along side #ifdef, so the macros are usually never expanded.   For instance the standard pattern of #include guards doesn't specify a value.

It's also common when you need something to conditionally expand.  This is frequently used when you need non-standard qualifiers on some platforms.  For instance windows DLLs require functions to have the dllexport storage class attribute so the following pattern is common:

Code: [Select]
#ifdef WINDOWS
#define DLLEXPORT dllexport
#else
#define DLLEXPORT
#endif

DLLEXPORT int foo(int x);

You can use the same pattern for different calling conventions (cdecl vs fastcall vs isr), section attributes, or anything else that would be an error in some situations.
 
The following users thanked this post: peter-h, newbrain

Offline gamalot

  • Super Contributor
  • ***
  • Posts: 1931
  • Country: au
  • Correct my English
    • Youtube
Re: Please help with this C syntax error
« Reply #33 on: June 13, 2025, 08:36:51 pm »
I am also surprised you can have a #define of nothing.

It is very common in include garding.

Code: [Select]
#ifndef FOO_H
#define FOO_H

......

#endif /* FOO_H */
I'm a poet, I didn't even know it. |  https://youtube.com/@gamalot | https://github.com/gamalot
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf