Solved

Help with a #define line of code

Posted on 2010-08-16
15
391 Views
Last Modified: 2012-06-27
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!!
0
Comment
Question by:really24
  • 5
  • 4
  • 2
  • +3
15 Comments
 
LVL 53

Expert Comment

by:Infinity08
ID: 33443898
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
 
LVL 53

Expert Comment

by:Infinity08
ID: 33443902
>> that is executed after passing the code to the compiler ?

that is executed *before* passing the code to the compiler
0
 
LVL 53

Expert Comment

by:Infinity08
ID: 33443904
Do you have a makefile ?
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33443906
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
 
LVL 84

Expert Comment

by:ozo
ID: 33443909
That is not valid C syntax
0
 
LVL 9

Expert Comment

by:masheik
ID: 33443942

/*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
 

Author Comment

by:really24
ID: 33444023
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 

Author Comment

by:really24
ID: 33444033
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
 
LVL 40

Expert Comment

by:evilrix
ID: 33444048
Maybe you could show us all the code as, often, context does help make things a lot clearer?
0
 
LVL 84

Expert Comment

by:ozo
ID: 33444074
It could be an assembly language macro
0
 

Author Comment

by:really24
ID: 33444100
/*!
   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
 

Author Comment

by:really24
ID: 33444111
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
 
LVL 30

Expert Comment

by:Zoppo
ID: 33444190
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
 
LVL 53

Accepted Solution

by:
Infinity08 earned 500 total points
ID: 33444359
>>    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
 

Author Closing Comment

by:really24
ID: 33444470
Thanks for your help! I really feel silly now. I guess I just wasn't paying attention.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode (http://en.wikipedia.org/wiki/Unicode)? They will have you believe that Unicode requires you to use…
The goal of this video is to provide viewers with basic examples to understand and use pointers in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to use strings and some functions related to them in the C programming language.

759 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now