invalid source character: '\' in macro

This is a discussion on invalid source character: '\' in macro within the C Programming forums, part of the General Programming Boards category; I am trying to compile some code that has multiline macros. Code: /* ***************************************************************** */ #define loop_body(rs,ls,step) \ x = ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    4

    Question invalid source character: '\' in macro

    I am trying to compile some code that has multiline macros.

    Code:
    /* ***************************************************************** */
    #define loop_body(rs,ls,step)                                  \
          x = S;                                /* feedback constant     */ \
          x ^= A[i+step-t5];                    /* end-around feedback   */ \
          x ^= A[i+step-t0];                    /* linear feedback       */ \
          x ^= ( A[i+step-t1] & A[i+step-t2] ); /* first quadratic term  */ \
          x ^= ( A[i+step-t3] & A[i+step-t4] ); /* second quadratic term */ \
          x ^= (x >> rs);                       /* right-shift           */ \
          A[i+step] = x ^ (x << ls);            /* left-shift            */  
    /* ***************************************************************** */
    Sun compiler gives this error:

    cc -c -g -w -o build/Debug/SunStudio_12.1-Solaris-x86/md6_compress.o md6_compress.c
    "md6_compress.c", line 218: invalid source character: '\'

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    I doubt this will make much difference but you could try putting it inside a block ({)
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    HelpingYouHelpUsHelpUsAll
    Join Date
    Dec 2007
    Location
    In your nightmares
    Posts
    223
    In addition, remove the '\'s. Worth a try.
    long time no C; //seige
    You miss 100% of the people you don't C;
    Code:
    if (language != LANG_C && language != LANG_CPP)
        drown(language);

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    > In addition, remove the '\'s. Worth a try.
    Macro definitions are always single line.
    So to write a complex macro, using \ is essential to keep the meaning of the macro intact.

    My only suggestion at the moment is to make sure there is no white-space (or other invisible characters) after each \
    Each should be immediately followed by a newline.
    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.

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    4
    There is no space after \. Even this c macro example doesn't compile:

    Code:
    #define SWAP(a, b)  {          \
                            a ^= b;         \
                            b ^= a;         \
                            a ^= b;         \
                        }
    invalid source character: '\'

    It compiles with gcc though. It seems that "\" isn't supported in sun compiler.

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,246
    I wonder if it's a line termination issue. Do you have dos2unix on your computer? If so, can you run it on your source file(s) and see if that fixes the compile error?
    bit∙hub [bit-huhb] n. A source and destination for information.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Look at some other source (reasonably large and complicated). I'd be surprised if the compiler was completely broken over something as basic as parsing \

    I agree with bithub, look at line terminations.
    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.

  8. #8
    Registered User
    Join Date
    Aug 2009
    Posts
    4

    Undefined symbol

    yes, dos2unix fixed the problem with /.

    Now I got another error:

    cc -m64 -o dist/Debug/SunStudio_12.1-Solaris-x86/md6 build/Debug/SunStudio_12.1-Solaris-x86/md6_compress.o build/Debug/SunStudio_12.1-Solaris-x86/md6sum.o build/Debug/SunStudio_12.1-Solaris-x86/md6_nist.o build/Debug/SunStudio_12.1-Solaris-x86/md6_mode.o
    Undefined first referenced
    symbol in file
    ticks build/Debug/SunStudio_12.1-Solaris-x86/md6sum.o


    function ticks() is defined in file md6sum.c like this:

    Code:
    #if defined _MSC_VER
    
    /* Microsoft */
    #include <intrin.h>
    #pragma intrinsic(__rdtsc)
    uint64_t ticks()
    {
    return __rdtsc();
    }
    
    #else
    
    /* GCC */
    #include <stdint.h>
    inline uint64_t ticks() {
      /* read timestamp counter */
      uint32_t lo, hi;
      asm volatile (
    		"xorl %%eax,%%eax \n        cpuid"
    		::: "%rax", "%rbx", "%rcx", "%rdx");
      asm volatile ("rdtsc" : "=a" (lo), "=d" (hi));
      return (uint64_t)hi << 32 | lo;
    } 
    
    #endif

  9. #9
    Registered User
    Join Date
    Aug 2009
    Posts
    4
    "extern inline" fixed that

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. sorting number
    By Leslie in forum C Programming
    Replies: 8
    Last Post: 05-20-2009, 04:23 AM
  2. Debug into Source
    By lehe in forum C++ Programming
    Replies: 4
    Last Post: 02-18-2009, 09:45 AM
  3. <string> to LPCSTR? Also, character encoding: UNICODE vs ?
    By Kurisu33 in forum C++ Programming
    Replies: 7
    Last Post: 10-09-2006, 12:48 AM
  4. about wide character and multiple byte character
    By George2 in forum C Programming
    Replies: 3
    Last Post: 05-22-2006, 08:11 PM
  5. Request for comments
    By Prelude in forum A Brief History of Cprogramming.com
    Replies: 15
    Last Post: 01-02-2004, 09:33 AM

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