Thread: invalid source character: backslash in macro

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

    Question invalid source character: backslash 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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > 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.

  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,268
    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 int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    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.

  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. Simple program, stopping invalid character infinite loop
    By samwillc in forum C++ Programming
    Replies: 16
    Last Post: 01-06-2013, 03:18 PM
  2. LPX-00217: invalid character 0 (U+0000)
    By sharmaremuk in forum C Programming
    Replies: 1
    Last Post: 03-03-2011, 04:56 AM
  3. Test of Equality for String Macro - Invalid?
    By Jesdisciple in forum C Programming
    Replies: 28
    Last Post: 01-25-2009, 04:47 PM
  4. invalid source character: <0xffffff80>
    By patso in forum C Programming
    Replies: 2
    Last Post: 04-14-2008, 08:52 PM
  5. W B : Invalid or incomplete multibyte or wide character
    By SoFarAway in forum C Programming
    Replies: 1
    Last Post: 02-19-2005, 12:40 AM