can't understand error message.

This is a discussion on can't understand error message. within the C Programming forums, part of the General Programming Boards category; i'm writing an application for smart card and when i compiled the program i got this error message: enc1.c(147): error ...

  1. #1
    Registered User
    Join Date
    Sep 2006
    Posts
    22

    can't understand error message.

    i'm writing an application for smart card and when i compiled the program i got this error message:

    enc1.c(147): error E8000: arguments to _code can only be locals, arguments, globals, or integer constants

    can someone please guide me through this..i'm running out of time.

  2. #2
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    So... no code, then?
    Sent from my iPadŽ

  3. #3
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    the line where the error occur is like this:

    Code:
    CHECKSUM(CLkeysat -1, apdu_group1.keyin, apdu_group1.S);
    CLkeysat-1 = length of block to be checksum

    apdu_group1.keyin = pointer to the block to be cheksum.

    apdu_group1.S = address of an unsign long that will be assigned the checksum.

    the definition part :


    Code:
    #pragma melpublic
    //unsigned char publicData[136];
    union {
        apdu_data pData;
    	apdu_data2 pData2;
        unsigned char pEncdata[16];
    	unsigned char pkeysat[CLkeysat];
    	unsigned int pKira1[1];
    	unsigned int pKira2[1];
    	//---baru----
    	unsigned long *S;
    	//unsigned char ceksum;
    	unsigned char keyin[CLkeysat-1];
    	//-----------
     } apdu_group1;
    Last edited by nurulhafiz; 09-11-2006 at 08:22 PM.

  4. #4
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Do you have a prototype of the CHECKSUM function?
    Sent from my iPadŽ

  5. #5
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    the prototype is like this

    Code:
    CHECKSUM(SIZE, BLOCK, SUM)
    i have include the multosarith.h
    Last edited by nurulhafiz; 09-11-2006 at 09:36 PM.

  6. #6
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    A macro? Ewww... use a function.

    No... no buts.... use a function. I don't know much about macros, but it wouldn't suprise me if it didn't take pointers. Hence, why your argument is invalid. Also, consider that the error could be somewhere in the macro itself, it's just pointing you to the line of the call, but that is getting replaced by the entire macro prior compile time.

    Long story short... use a function. It will make debugging much easier.
    Last edited by SlyMaelstrom; 09-11-2006 at 09:40 PM.
    Sent from my iPadŽ

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    oooo..ok..i'll try..

  8. #8
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Quote Originally Posted by SlyMaelstrom
    A macro? Ewww... use a function.

    No... no buts.... use a function. I don't know much about macros, but it wouldn't suprise me if it didn't take pointers
    Long story short... learn about macros. If you don't know about something, you can't really give advice regarding it.

    A macro is simple compile-time text replacement. That's all. Macros don't check type, because they don't care. They can "take pointers" or whatever you feel like passing to them. (Or nothing for that matter.)

    All they are is text replacement.


    Quzah.
    Hope is the first step on the road to disappointment.

  9. #9
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    so can u help me with the error?

  10. #10
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,066
    Quote Originally Posted by quzah
    A macro is simple compile-time text replacement. That's all. Macros don't check type, because they don't care. They can "take pointers" or whatever you feel like passing to them. (Or nothing for that matter.)

    All they are is text replacement.
    Yes, fine, but I wasn't really sure of the fundementals of how they worked. For instance if you have a macro
    Code:
    #define mult(x,y) x * y
    
    /* Assume foo and
       bar are defined as ints
       with values 5 and 3, respectively
    */
    /* ...and the macro is called as */
    
    int ans = mult(foo,bar);
    
    // When it's replaced with the macro code is the replacement:
    //     int ans = foo * bar;
    // or is it
    //     int ans = 5 * 3;
    Which is why I wasn't sure if addresses were cool with macros. I guess they don't check what it is at all regardless of how bad the result can be. I guess in the end, it wouldn't make much of a difference. I shouldn't have jumped to a conclusion, there.

    EDIT: Hmm... got curious and tested in on GCC. It seemed to replace it with
    Code:
    int ans = foo * bar;
    I guess that's expect as there is no reason for the preprocessor to resolve the values of the variables. So that answers that... should have been thinking. I wasn't.
    Last edited by SlyMaelstrom; 09-11-2006 at 09:59 PM.
    Sent from my iPadŽ

  11. #11
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    Paste the expansion of your CHECKSUM macro, from your header file.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    22
    is this it?

    Code:
    /* SmartDeck arbitrary sized number support.
       Copyright (c) 2001 Aspects Software Ltd.
    */
    
    #ifndef __multosarith_H
    #define __multosarith_H
    
    #include <melasm.h>
    
    /* support for N byte block arithmetic */
    #define BLOCKCAST(N) *(struct { unsigned char __x[N]; }*)
    
    /* OP N block at RHS to block at LHS */
    #define ASSIGN_BINARY_OPN(N, OP, LHS, RHS) \
      __push(BLOCKCAST(N)(__typechk(unsigned char *, RHS)));	\
      __code(OP, __typechk(unsigned char *, LHS), N);		\
      __code(POPN, N)
    
    /* OP N blocks at OP1 and OP2 and store in SUM */
    #define BINARY_OPN(N, OP, SUM, OP1, OP2)	\
    do {								\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, OP1)));	\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, OP2))); 	\
      __code(OP, N);        					\
      __code(POPN, N);      					\
      __code(STORE, __typechk(unsigned char *, SUM), N);		\
    } while (0)
    
    /* OP N block */
    #define UNARY_OPN(N, OP, V) \
      __code(OP, V, N);
    
    #define ASSIGN_ADDN(N, LHS, RHS) ASSIGN_BINARY_OPN(N, ADDN, LHS, RHS)
    
    #define ADDN(N, SUM, OP1, OP2) BINARY_OPN(N, ADDN, SUM, OP1, OP2)
    
    #define ASSIGN_ANDN(N, LHS, RHS) ASSIGN_BINARY_OPN(N, ANDN, LHS, RHS)
    
    #define ANDN(N, SUM, OP1, OP2) BINARY_OPN(N, ANDN, SUM, OP1, OP2)
    
    #define ASSIGN_ORN(N, LHS, RHS) ASSIGN_BINARY_OPN(N, ORN, LHS, RHS)
    
    #define ORN(N, SUM, OP1, OP2) BINARY_OPN(N, ORN, SUM, OP1, OP2)
    
    #define ASSIGN_SUBN(N, LHS, RHS) ASSIGN_BINARY_OPN(N, SUBN, LHS, RHS)
    
    #define SUBN(N, SUM, OP1, OP2) BINARY_OPN(N, SUBN, SUM, OP1, OP2)
    
    #define ASSIGN_XORN(N, LHS, RHS) ASSIGN_BINARY_OPN(N, XORN, LHS, RHS)
    
    #define XORN(N, SUM, OP1, OP2) BINARY_OPN(N, XORN, SUM, OP1, OP2)
    
    #define CLEARN(N, V) UNARY_OPN(N, CLEARN, V)
    
    #define INCN(N, V) UNARY_OPN(N, INCN, V)
    
    #define DECN(N, V) UNARY_OPN(N, DECN, V);
    
    #define NOTN(N, V) UNARY_OPN(N, NOTN, V);
    
    #define TESTN(N, V) UNARY_OPN(N, TESTN, V);
    
    /* Truncating assignment multiplication - note carry flag will NOT be set */
    #define ASSIGN_MULN(N, LHS, RHS) \
    do {                             \
      __push(BLOCKCAST(N)(__typechk(unsigned char *, LHS)));  \
      __push(BLOCKCAST(N)(__typechk(unsigned char *, RHS)));  \
      __code(PRIM, 0x10, N); \
      __code(STORE, LHS, N); \
      __code(POPN, N);		 \
    } while (0)
    
    /* N byte multiplication product must be 2 * N sized */
    #define MULN(N, PRODUCT, OP1, OP2) \
    do {								\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, OP1)));	\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, OP2)));	\
      __code(PRIM, 0x10, N);					\
      __code(STORE, __typechk(unsigned char *, PRODUCT), N*2);	\
    } while (0)
    
    /* N byte division QUOTIENT = NUMERATOR / DEMONIMATOR, REMAINDER = NUMERATOR % DENOMINATOR */
    #define DIVN(N, NUMERATOR, DENOMINATOR, QUOTIENT, REMAINDER) \
    do {									\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, NUMERATOR)));		\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, DENOMINATOR)));	\
      __code(PRIM, 0x08, N);						\
      __code(STORE, __typechk(unsigned char *, REMAINDER), N);		\
      __code(STORE, __typechk(unsigned char *, QUOTIENT), N);		\
    } while (0)
    
    /* assignment division - quotient replaces numerator and remainder replaces denomator */
    #define ASSIGN_DIVN(N, NUMERATOR, DENOMINATOR) \
      DIVN(N, NUMERATOR, DENOMINATOR, NUMERATOR, DENOMINATOR)
    
    /*  RES = DATA << NUMBITS */
    #define SHLN(N, DATA, NUMBITS, RES) \
    do {								\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, DATA)));	\
      __code(PRIM, 0x02, N, NUMBITS);				\
      __code(STORE, __typechk(unsigned char *, RES), N);		\
    } while (0)
    
    /* DATA <<= NUMBITS */
    #define ASSIGN_SHLN(N, DATA, NUMBITS) \
      SHLN(N, DATA, NUMBITS, DATA)
    
    /*  RES = DATA >> NUMBITS */
    #define SHRN(N, DATA, NUMBITS, RES)	\
    do {								\
      __push(BLOCKCAST(N)(__typechk(unsigned char *, DATA)));	\
      __code(PRIM, 0x03, N, NUMBITS);				\
      __code(STORE, __typechk(unsigned char *, RES), N);		\
    } while (0)
    
    /* DATA >>= NUMBITS */
    #define ASSIGN_SHRN(N, DATA, NUMBITS) \
      SHRN(N, DATA, NUMBITS, DATA)
    
    #define CMPN(N, OP1, OP2) memcmp(OP1, OP2, N)
    
    /* N byte copy */
    #define COPYN(N, DEST, SRC)      \
    do {							\
      __push(__typechk(unsigned char *, DEST));		\
      __push(__typechk(unsigned char *, SRC));		\
      __code(PRIM, 0x0e, N);				\
    } while (0)
    
    #define CHECKSUM(SIZE, BLOCK, SUM) \
    do {							\
      __push(__typechk(unsigned int, SIZE));		\
      __push(__typechk(unsigned char *, BLOCK));  		\
      __code(PRIM, 0x82);					\
      __code(STORE, __typechk(unsigned long *, SUM), 4);	\
    } while (0)
    
    #endif

  13. #13
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    And what are the definitions of __code and PRIM?
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  14. #14
    Registered User
    Join Date
    Mar 2006
    Posts
    725
    ...I'm having this feeling that you'll need to contact whoever wrote the code and ask them about it. Maybe look for code documentation. Probably someone intended CHECKSUM to be used this way and not that way or that other way, you know.
    Code:
    #include <stdio.h>
    
    void J(char*a){int f,i=0,c='1';for(;a[i]!='0';++i)if(i==81){
    puts(a);return;}for(;c<='9';++c){for(f=0;f<9;++f)if(a[i-i%27+i%9
    /3*3+f/3*9+f%3]==c||a[i%9+f*9]==c||a[i-i%9+f]==c)goto e;a[i]=c;J(a);a[i]
    ='0';e:;}}int main(int c,char**v){int t=0;if(c>1){for(;v[1][
    t];++t);if(t==81){J(v[1]);return 0;}}puts("sudoku [0-9]{81}");return 1;}

  15. #15
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    > apdu_group1.keyin, apdu_group1.S
    Why is it a union?
    Attempting to use one member will trash the other.

    Are you "REALLY" sure that S should be a pointer, or did you just make it a pointer to make something else shut the hell up?

    unsigned long *S; .... apdu_group1.S
    vs.
    unsigned long S; .... &apdu_group1.S
    would both satisfy some type constraint somewhere (by being a pointer to an unsigned int), but the results are very different.

    Do you have any other example uses of CHECKSUM in your code which do the right thing?

    Which compiler are you using?
    Is this for some embedded system (not a desktop machine)?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21