none
error C2059: syntax error : 'string'

    Question

  • Hi All

    I have following code in my .h file

    extern "C" {

    __inline short cosi_atomic_add16(volatile short *p,short n);

    }

    here is the code in .asm file

    _DATA SEGMENT

    ;cosi_atomic_add16

    p QWORD 0

    n WORD 0

    value WORD 0

    _Data ENDS

    .CODE

     

    cosi_atomic_add16 PROC

    mov ax,n

    mov rax,p

    lock xadd [rax],ax

    mov value,ax

    ret

    cosi_atomic_add16 ENDP

    END

     

    when i complie the above code i get following error

    Error 282 error C2059: syntax error : 'string'

    in .h file

    Please help me

    Thanks,
    rahul

    Thursday, December 10, 2009 5:20 AM

Answers

  • extern "C" can only be used with C++, not with C. Try this:

    #ifdef __cplusplus
    extern "C" {
    #endif
    __inline short cosi_atomic_add16(volatile short *p,short n);
    #ifdef __cplusplus
    }
    #endif

    - Wayne
    • Marked as answer by Nancy Shao Friday, December 11, 2009 9:14 AM
    Thursday, December 10, 2009 6:33 AM

All replies

  • I don't see the word "string" at all in the code that you have posted.
    Check which line the error occurs and post the relevant code.

    If you're using the stl string class, you're probably missing the std namespace.
    So you could rewrite it as std::string.

    «_Superman_»
    Microsoft MVP (Visual C++)
    Thursday, December 10, 2009 5:29 AM
  • Hi

    Thanks for your reply.

    Tha error occurs at  extern "C" line

    extern "C" {

    __inline short cosi_atomic_add16(volatile short *p,short n);

    }

    Thanks,
    rahul

    Thursday, December 10, 2009 6:09 AM
  • I feel, you need to initilize p and n before passing to cosi_atomic_add16.
    Thanks Mike --------Please mark as answer if it is useful----------
    Thursday, December 10, 2009 6:26 AM
  • extern "C" can only be used with C++, not with C. Try this:

    #ifdef __cplusplus
    extern "C" {
    #endif
    __inline short cosi_atomic_add16(volatile short *p,short n);
    #ifdef __cplusplus
    }
    #endif

    - Wayne
    • Marked as answer by Nancy Shao Friday, December 11, 2009 9:14 AM
    Thursday, December 10, 2009 6:33 AM
  • Thanks

    now its working now....:)

    Regards,
    rahul
    Thursday, December 10, 2009 8:11 AM