Menu

#19 Improve the ugly looking shared C/ASM header file cbmforng.i

not categorized
closed
Womo
6
2020-07-06
2010-04-28
Womo
No

In a discussion on the CC65 mailing list, one came up with ideas for further improvements to the concept of constructing a shared C/ASM header file with macro definitions:

Steve Davison wrote there:

[....] However I have a number of suggestions that could make it far more legible and usable:

  • Instead of _CMT(str) macro consuming str, how about a _CMT() mac that turns the just inserts a ';' or a '//' ?
  • In order to be more than a parlor trick, I think you would have to have a full, standard set of macros, a la OCTETDECL, that are predefined in a library. Lets everyone speak the same language, and avoids a lot of reinvention.
  • (..continued..) The language-specific macro defines should not be duplicated in every file that needs an .idh include, they should be in the .idh file itself. More encapsulated, less clutter, less prone to errors.
  • Further, they wouldn't actually be defined in the .idh files themselves; the .idh would simply include the standard macro library as described above. The really neat part is that getting the definitions for the appropriate language could be accomplished using Christian's method.
    [...]
    //////// THIS IS COOL... /////////
    If you haven't done it already, take Christian's duplicitous header code and look at it with syntax highlighting, both C and assembler. It's kinda like turning on 2 different neon signs that are under camouflage.

Prior the Steve's mail, Christian Grössler wrote:


;/ include file for assembler & C
; * Christian Groessler
;
/

;/ Avoid double inclusion in C /
;/
.if 0
;
/

ifndef C_AND_ASM_INCLUDED

define C_AND_ASM_INCLUDED

;/
.endif
;
/

;/ some constants
;
/ enum MY_CONSTANTS { /
MY_CONSTANT_1 = 123 ;
/ MY_CONSTANT_1 = 123, /
MY_CONSTANT_2 = 456 ;
/ MY_CONSTANT_2 = 456, /
;
/ };

;/ a structure
.struct MY_STRUCT ;
/ typedef struct MY_STRUCT
{ /
MEMBER1 .word 2 ;
/ unsigned short
MEMBER1[2]; /
MEMBER2 .byte 2 ;
/ unsigned char
MEMBER2[2]; /
.endstruct ;
/ } MY_STRUCT_T;

;/
.if 0
;
/

endif // C_AND_ASM_INCLUDED

;/
.endif
;
/

;/ End of Include file /

The neat trick of Christian's code is using the ";". In CA65-Assembler this introduces an until-the-end-of-the-line comment. In C, at the very most places an additional ";" does not have any futher syntactical or semantical meaning. Therefore the ";" can be used to hide things from the assmebler in one-line comments. In native C these lines are not hidden and therefore can introduce special pre-process definitions to the C compiler; here to hide ASM instructions from the C compiler. And so on...

Womo

Discussion

  • Spiro Trikaliotis

    • Group: next_release --> not categorized
     
  • Spiro Trikaliotis

     
  • Spiro Trikaliotis

    • status: open --> closed
     

Anonymous
Anonymous

Add attachments
Cancel





MongoDB Logo MongoDB