You are not logged in.

#1 2008-09-13 21:52:58

curve
Member
Registered: 2008-09-09
Posts: 12

Proper g++ escape sequences

I was cleaning out an old pen drive and ran across this cpp program from a college class.  I know it compiled fine back then in VS2003, but I tried compiling it with g++ just now and it doesn't accept any of the escape sequences.

Did I handle the escape sequences in a non-standardized way or something?

There's a ton of them throughout the whole program, so I'll just show a couple snippets:

Errors:

...
Scanner.cpp:11208:8: error: unknown escape sequence '\{'
Scanner.cpp:11212:8: error: unknown escape sequence '\}'
...

Corresponding code:

...
        //All special symbols except $ accept current token as an identifier
        //    and then consumes the special symbol
        case '\{': {
            accept_id();
            accept_special();
        } break;
        case '\}': {
            accept_id();
            accept_special();
        } break;
...

Offline

#2 2008-09-13 22:09:11

dante4d
Member
From: Czech Republic
Registered: 2007-04-14
Posts: 176

Re: Proper g++ escape sequences

Case statements accept only integer values, where '{' would be char, which is convertible to int. Looks like '\{' was escape for VS2003 but g++ doesn't know it? I did lot of coding in VC++ and I don't remember using \{ escape sequence. It isn't anything standard I believe. While with Micro$oft products, anything is possible, just look through their include files or old MFC classes (I mean tons of nonstandart extensions to C/C++ which sometimes don't work even with VC++ compiler) tongue.

Offline

#3 2008-09-13 22:53:15

curve
Member
Registered: 2008-09-09
Posts: 12

Re: Proper g++ escape sequences

Hmm I don't have my vs2003 anymore, but I'll grab the 2008 express edition sometime and check.

Offline

#4 2008-09-14 09:05:20

robertp
Member
From: Warszawa, Poland
Registered: 2007-09-11
Posts: 123

Re: Proper g++ escape sequences

In C++ there are no (and never were) \{ and \} escape sequences. Just change:

'\{' to '{'
'\}' to '}'

and the program should compile.

Offline

#5 2008-09-14 15:54:44

curve
Member
Registered: 2008-09-09
Posts: 12

Re: Proper g++ escape sequences

I just tried removing all the escape sequences.. g++ builds it with no problems and runs it properly.

I also tried it with VS just now..
VS without escape sequences: it builds fine, but will not run.. gives unhandled exception.
VS with escape sequences: it gives "unrecognized character escape sequence" warnings, but it runs properly.

Not sure what's wrong with the code, but would have been nice if my professor had pointed it out.

Offline

Board footer

Powered by FluxBB