Trailing spaces after backslash delimiter – Programmers nightmare.

31 03 2008

Icon Description
Usually we used to have spaces after semi columns. Since C++ ignore whitespace, its not a problem. But in Visual C++ 6.0 that is not the case always. If you put spaces after the backslash delimiter(\), it will become one of the worst bugs that you encounter.

Usually we use backslash delimiter to concatenate lines – mostly while writing macros. See the following macro.

    Value = Value + 1; \ » » »
    Value = Value - 1;

In the macro, instead of » char, put some tab or space and then compile. You will get a strange error as follows.

error C2501: 'Value' : missing storage-class or type specifiers

Icon How Can I Do It?
One of the defensive mechanism is – always enable “View whitespace” by pressing Ctrl+Shift+8. So take care next time and don’t spend hrs on these silly bugs as I did years before.

Note that its just a implementation behavior in Visual C++ 6.0 and may not found in other compilers or upcoming Visual C++ versions.

Thanks to Hemant for pointing out my implicit biasing towards VisualStudio 6.0. I forgot to specify that its just a Visual studio behavior.

Targeted Audience – Intermediate.



2 responses

18 06 2008

This is the problem with VC++ compiler (VS 6.0 and VS 2005 )
I have tried the code on Dev-c++ ,gcc compiler

18 06 2008

Indeed Hemant. You are right. Its just a Visual studio bug. But just now i’ve noticed that i didn’t mentioned that and instead I’ve written in context of C++. Thanks for pointing it out. I’ll correct it now.

Keep watching…


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: