I have tried to do this but I'm unable. How can i declare a number of variables with legal and illegal names (such as int double = 0;), so that you can see how the compiler reacts.
-
3simple, you don't. If you have illegal syntaxes your compiler isn't going to build regardless of what you try/do – Mo Patel Oct 20 '14 at 18:52
-
Simply write some variables in your compiler and watch what happens. I'm confused on how you are unable to do this? What did you try? – Grice Oct 20 '14 at 18:55
-
actually i m new to C++ .i don't know how to solve it out. – Kashif Oct 20 '14 at 18:57
-
Look at [Valid Variable Names](http://www.c4learn.com/cplusplus/cpp-variable-naming/). Have you created a program before? – Grice Oct 20 '14 at 19:08
-
2"How can I declare variables with illegal names?" "I have tried to do this but I'm unable." - what do you think "illegal" means? – Crowman Oct 20 '14 at 19:38
-
See [C++ keywords](http://en.cppreference.com/w/cpp/keyword): "..these keywords [including 'double'] are *not available for re-definition or overloading.*" – user2864740 Oct 20 '14 at 19:39
-
if you just want to try out simple code-snippets you can just use [ideone](http://ideone.com/jNL20y) otherwise just use a C++ compiler – PeterT Oct 20 '14 at 19:43
2 Answers
The short answer to this is DON'T DO IT.
There are a number of reserved words in the C and C++ standards that should not be used for any purpose other than which they are originally intended. Going out of your way to recycle these for your own perverse purpose is going to create problems for a lot of people. One of those people might be yourself fin the future when you have to fix a bug.
If you want to use double
as a variable name, the best method to make this happen is to successfully petition the C++ committee constructing the next standard to allow it. Then you will have a valid program.
If you want to see how the compiler behaves when encountering this problem, create tiny programs that are as small as practical. For example:
// invalid_double.c
int double = 0;
You'll immediately see a syntax error when trying to compile that. Repeat as necessary with other keywords. This is often how things like configure
run tests to verify the behaviour and capabilities of the local compiler.
Your compiler will probably halt compilation at the first invalid use of a keyword so you may need to construct one file per experiment. Subsequent errors in the same file may be ignored, such as if you had int class = 0

- 208,517
- 23
- 234
- 262
it is like a Quote from (Programming__Principles_and_Practice_Using C++),I think the auther asks us to try it and see the error no more(just we try it ourselfes).
-
1Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jun 07 '22 at 01:12