• C

Help with a #define line of code

Hi,
I found this when reading some C code. Can someone explain how to read this define statement in terms of Syntax?

#define[DEFINE_INTVEC(][,$1);][zdata at $0 struct INTVEC $1;]

Thanks!!
really24Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Infinity08Commented:
That doesn't look like a valid C #define to me. Maybe there is another pre-compiler step that is executed after passing the code to the compiler ?
0
Infinity08Commented:
>> that is executed after passing the code to the compiler ?

that is executed *before* passing the code to the compiler
0
Infinity08Commented:
Do you have a makefile ?
0
ON-DEMAND: 10 Easy Ways to Lose a Password

Learn about the methods that hackers use to lift real, working credentials from even the most security-savvy employees in this on-demand webinar. We cover the importance of multi-factor authentication and how these solutions can better protect your business!

evilrixSenior Software Engineer (Avast)Commented:
What is the context of this? The code you've posted isn't a valid C Preprocessor #define. Are you sure this code isn't meant to be pre-parsed, for instance by a Perl script?
0
ozoCommented:
That is not valid C syntax
0
masheikCommented:

/*Macro format looks like below */

#define <identifier> <Replacement token List>
#define <identifier>(<parameter list>) <replacement token list>

/* In your case it is not valid one */

Open in new window

0
really24Author Commented:
First of all, thanks for all the quick replies. Ok, I guess the consensus is that this is some strange syntax.

There is no other pre-parser or pre-pre processing that I know of.

Anyway, I think what is happening is that the the writer was trying to make some kind of macro or format so that later in the code they can write this kind of syntax in another header file. Notice the "at" keyword, which isn't a C Keyword at all.

zdata at 0xE400 volatile BYTE GPIF_WAVE_DATA[128];

using this

#define[DEFINE_INTVEC(][,$1);][zdata at $0 struct INTVEC $1;]

where DEFINE_INTVEC() is

#define[DEFINE_INTVEC(][,$1);][    .org $0
      reti]
    _asm
    .area ABSCODE (ABS,CODE)
    .org 0x0000
ENTRY:
      ljmp #0x0200
INTVECS;
    .org 0x01b8
INTVEC_DUMMY:
        reti
    .area CSEG    (CODE)
    _endasm;    

Sorry, that my question turned out strange. The more I dig the stranger it is getting.
0
really24Author Commented:
Then can you not use square brackets in a #define macro?

By the way this code is compiled with SDCC for an 8051 based processor.
0
evilrixSenior Software Engineer (Avast)Commented:
Maybe you could show us all the code as, often, context does help make things a lot clearer?
0
ozoCommented:
It could be an assembly language macro
0
really24Author Commented:
/*!
   ZTEX Firmware Kit for EZ-USB Microcontrollers
   Copyright (C) 2009-2010 ZTEX e.K.
   http://www.ztex.de

   This program is free software; you can redistribute it and/or modify
   it under the terms of the GNU General Public License version 3 as
   published by the Free Software Foundation.

   This program is distributed in the hope that it will be useful, but
   WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program; if not, see http://www.gnu.org/licenses/.
!*/

/*
   EZ-USB Autovectors
*/

#ifndef[EZINTAVECS_H]
#define[EZINTAVECS_H]

#include[ztex-utils.h]

struct INTVEC {
    BYTE op;
    BYTE addrH;
    BYTE addrL;
};

#define[INTVECS;][DEFINE_INTVEC(0x0003,INT0VEC_IE0);
DEFINE_INTVEC(0x000b,INT1VEC_T0);
DEFINE_INTVEC(0x0013,INT2VEC_IE1);
DEFINE_INTVEC(0x001b,INT3VEC_T1);
DEFINE_INTVEC(0x0023,INT4VEC_USART0);
DEFINE_INTVEC(0x002b,INT5VEC_T2);
DEFINE_INTVEC(0x0033,INT6VEC_RESUME);
DEFINE_INTVEC(0x003b,INT7VEC_USART1);
DEFINE_INTVEC(0x0043,INT8VEC_USB);
DEFINE_INTVEC(0x004b,INT9VEC_I2C);
DEFINE_INTVEC(0x0053,INT10VEC_GPIF);
DEFINE_INTVEC(0x005b,INT11VEC_IE5);
DEFINE_INTVEC(0x0063,INT12VEC_IE6);
DEFINE_INTVEC(0x0100,INTVEC_SUDAV);
DEFINE_INTVEC(0x0104,INTVEC_SOF);
DEFINE_INTVEC(0x0108,INTVEC_SUTOK);
DEFINE_INTVEC(0x010C,INTVEC_SUSPEND);
DEFINE_INTVEC(0x0110,INTVEC_USBRESET);
DEFINE_INTVEC(0x0114,INTVEC_HISPEED);
DEFINE_INTVEC(0x0118,INTVEC_EP0ACK);
DEFINE_INTVEC(0x0120,INTVEC_EP0IN);
DEFINE_INTVEC(0x0124,INTVEC_EP0OUT);
DEFINE_INTVEC(0x0128,INTVEC_EP1IN);
DEFINE_INTVEC(0x012C,INTVEC_EP1OUT);
DEFINE_INTVEC(0x0130,INTVEC_EP2);
DEFINE_INTVEC(0x0134,INTVEC_EP4);
DEFINE_INTVEC(0x0138,INTVEC_EP6);
DEFINE_INTVEC(0x013C,INTVEC_EP8);
DEFINE_INTVEC(0x0140,INTVEC_IBN);
DEFINE_INTVEC(0x0148,INTVEC_EP0PING);
DEFINE_INTVEC(0x014C,INTVEC_EP1PING);
DEFINE_INTVEC(0x0150,INTVEC_EP2PING);
DEFINE_INTVEC(0x0154,INTVEC_EP4PING);
DEFINE_INTVEC(0x0158,INTVEC_EP6PING);
DEFINE_INTVEC(0x015C,INTVEC_EP8PING);
DEFINE_INTVEC(0x0160,INTVEC_ERRLIMIT);
DEFINE_INTVEC(0x0170,INTVEC_EP2ISOERR);
DEFINE_INTVEC(0x0174,INTVEC_EP4ISOERR);
DEFINE_INTVEC(0x0178,INTVEC_EP6ISOERR);
DEFINE_INTVEC(0x017C,INTVEC_EP8ISOERR);
DEFINE_INTVEC(0x0180,INTVEC_EP2PF);
DEFINE_INTVEC(0x0184,INTVEC_EP4PF);
DEFINE_INTVEC(0x0188,INTVEC_EP6PF);
DEFINE_INTVEC(0x018C,INTVEC_EP8PF);
DEFINE_INTVEC(0x0190,INTVEC_EP2EF);
DEFINE_INTVEC(0x0194,INTVEC_EP4EF);
DEFINE_INTVEC(0x0198,INTVEC_EP6EF);
DEFINE_INTVEC(0x019C,INTVEC_EP8EF);
DEFINE_INTVEC(0x01A0,INTVEC_EP2FF);
DEFINE_INTVEC(0x01A8,INTVEC_EP6FF);
DEFINE_INTVEC(0x01AC,INTVEC_EP8FF);
DEFINE_INTVEC(0x01B0,INTVEC_GPIFDONE);
DEFINE_INTVEC(0x01B4,INTVEC_GPIFWF);]

#define[DEFINE_INTVEC(][,$1);][zdata at $0 struct INTVEC $1;]
INTVECS;
#udefine[DEFINE_INTVEC(]

void abscode_intvec() _naked
{
#define[DEFINE_INTVEC(][,$1);][    .org $0
      reti]
    _asm
    .area ABSCODE (ABS,CODE)
    .org 0x0000
ENTRY:
      ljmp #0x0200
INTVECS;
    .org 0x01b8
INTVEC_DUMMY:
        reti
    .area CSEG    (CODE)
    _endasm;    
}    

#udefine[INTVECS;]
#udefine[DEFINE_INTVEC(]


/* Init an interrupt vector */
#define[INIT_INTERRUPT_VECTOR(][,$1);][{
    $0.op=0x02;
    $0.addrH=((unsigned short)(&$1)) >> 8;
    $0.addrL=(unsigned short)(&$1);
}]


/* Enable USB autovectors */
#define[ENABLE_AVUSB;][{
    INT8VEC_USB.op=0x02;
    INT8VEC_USB.addrH = 0x01;
    INT8VEC_USB.addrL = 0xb8;
    INTSETUP |= 8;
}]


/* Disable USB autovectors */
#define[DISABLE_AVUSB;][INTSETUP &= ~8;]


/* Enable GPIF autovectors */
#define[ENABLE_AVGPIF;][{
    INT10VEC_GPIF.op=0x02;
    INT10VEC_GPIF.addrH = 0x01;
    INT10VEC_GPIF.addrL = 0xb8;
    INTSETUP |= 3;
}]


/* Disable GPIF autovectors */
#define[DISABLE_AVPGIF;][INTSETUP &= ~3;]


#endif   /* INTAVECS_H */
0
really24Author Commented:
My main point is just to understand using the #define syntax in a deeper way and understanding macros. It just seemed like interesting syntax.

That's why I asked.
0
ZoppoCommented:
Hi really24,

unfortunateley you didn't answer 'Infinity08's question: Do you have a makefile? If so could you post it's content?

ZOPPO
0
Infinity08Commented:
>>    ZTEX Firmware Kit for EZ-USB Microcontrollers

ZTEX uses a pre-compiler called bmp (see the ZTEX SDK), which transforms the input file into a valid C file (at least, it's valid for the SDCC compiler, because it still uses some compiler extensions).

That confirms my original suspicion (http:#33443898) ;)
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
really24Author Commented:
Thanks for your help! I really feel silly now. I guess I just wasn't paying attention.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.