#define - cannot define/undefine preprocessor symbols after first token in file 
Author Message
 #define - cannot define/undefine preprocessor symbols after first token in file

Hi

please can you tell me what I need to define in my file...

Using System;
Using System.Drawing;
.
.
.

#define Number

namespace Bobby
{

Quote:
}

I have tried defining with a value anmd without, with semi-colon and
without......

Thanks in advance



Tue, 02 Nov 2004 20:03:01 GMT  
 #define - cannot define/undefine preprocessor symbols after first token in file
Miss Ellie,

    When using #define, you are only defining a flag of sorts, and your
original declaration was correct.  The only thing you can do with this is
check for the existence of the flag, like so:

#if Number

#endif

    And so on.  I think that what you are trying to do is create a macro,
which you can not do in C#.  What are you trying to do?

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Hi

> please can you tell me what I need to define in my file...

> Using System;
> Using System.Drawing;
> .
> .
> .

> #define Number

> namespace Bobby
> {
> }

> I have tried defining with a value anmd without, with semi-colon and
> without......

> Thanks in advance



Tue, 02 Nov 2004 20:15:51 GMT  
 #define - cannot define/undefine preprocessor symbols after first token in file
Thanks for the reply

I am trying to reproduce the C++ #define, i.e. I want to declare a global
constant

eg
#define fred 2

and use fred throughout my class

is this of any help?

Thx

Miss Ellie


Quote:
> Miss Ellie,

>     When using #define, you are only defining a flag of sorts, and your
> original declaration was correct.  The only thing you can do with this is
> check for the existence of the flag, like so:

> #if Number

> #endif

>     And so on.  I think that what you are trying to do is create a macro,
> which you can not do in C#.  What are you trying to do?

> --
>                - Nicholas Paldino [.NET MVP]



> > Hi

> > please can you tell me what I need to define in my file...

> > Using System;
> > Using System.Drawing;
> > .
> > .
> > .

> > #define Number

> > namespace Bobby
> > {
> > }

> > I have tried defining with a value anmd without, with semi-colon and
> > without......

> > Thanks in advance



Tue, 02 Nov 2004 20:45:56 GMT  
 #define - cannot define/undefine preprocessor symbols after first token in file
Miss Ellie,

    You can not do this.  You will have to create a static member on a class
and then use that.  You can declare the member as const or readonly and it
will prevent others from setting it.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> Thanks for the reply

> I am trying to reproduce the C++ #define, i.e. I want to declare a global
> constant

> eg
> #define fred 2

> and use fred throughout my class

> is this of any help?

> Thx

> Miss Ellie

wrote

> > Miss Ellie,

> >     When using #define, you are only defining a flag of sorts, and your
> > original declaration was correct.  The only thing you can do with this
is
> > check for the existence of the flag, like so:

> > #if Number

> > #endif

> >     And so on.  I think that what you are trying to do is create a
macro,
> > which you can not do in C#.  What are you trying to do?

> > --
> >                - Nicholas Paldino [.NET MVP]



> > > Hi

> > > please can you tell me what I need to define in my file...

> > > Using System;
> > > Using System.Drawing;
> > > .
> > > .
> > > .

> > > #define Number

> > > namespace Bobby
> > > {
> > > }

> > > I have tried defining with a value anmd without, with semi-colon and
> > > without......

> > > Thanks in advance



Tue, 02 Nov 2004 20:49:34 GMT  
 #define - cannot define/undefine preprocessor symbols after first token in file

Quote:

> I am trying to reproduce the C++ #define, i.e. I want to declare a
> global constant

> eg
> #define fred 2

This is not possible with C#...

You can only 'define' something but without any value!
So you can only check if it IS defined or it IS NOT defined.
You cannot check any value...

There are a big discussion if you really need a define with a value...

You can use e.g. public const ...

--
Greetings
  Jochen



Tue, 02 Nov 2004 20:56:20 GMT  
 #define - cannot define/undefine preprocessor symbols after first token in file
hah well, time to lose the c++ shackles and think in another tongue

Thnaks both for your help

Quote:
> Thanks for the reply

> I am trying to reproduce the C++ #define, i.e. I want to declare a global
> constant

> eg
> #define fred 2

> and use fred throughout my class

> is this of any help?

> Thx

> Miss Ellie

wrote

> > Miss Ellie,

> >     When using #define, you are only defining a flag of sorts, and your
> > original declaration was correct.  The only thing you can do with this
is
> > check for the existence of the flag, like so:

> > #if Number

> > #endif

> >     And so on.  I think that what you are trying to do is create a
macro,
> > which you can not do in C#.  What are you trying to do?

> > --
> >                - Nicholas Paldino [.NET MVP]



> > > Hi

> > > please can you tell me what I need to define in my file...

> > > Using System;
> > > Using System.Drawing;
> > > .
> > > .
> > > .

> > > #define Number

> > > namespace Bobby
> > > {
> > > }

> > > I have tried defining with a value anmd without, with semi-colon and
> > > without......

> > > Thanks in advance



Tue, 02 Nov 2004 21:01:53 GMT  
 #define - cannot define/undefine preprocessor symbols after first token in file
Didn't C++ come out with const so that preprocessor directives do not need
to be used like this? (In other words, C# is pretty much the same in this
respect.)

-glenn-


Quote:
> hah well, time to lose the c++ shackles and think in another tongue

> Thnaks both for your help


> > Thanks for the reply

> > I am trying to reproduce the C++ #define, i.e. I want to declare a
global
> > constant

> > eg
> > #define fred 2

> > and use fred throughout my class

> > is this of any help?

> > Thx

> > Miss Ellie

> wrote

> > > Miss Ellie,

> > >     When using #define, you are only defining a flag of sorts, and
your
> > > original declaration was correct.  The only thing you can do with this
> is
> > > check for the existence of the flag, like so:

> > > #if Number

> > > #endif

> > >     And so on.  I think that what you are trying to do is create a
> macro,
> > > which you can not do in C#.  What are you trying to do?

> > > --
> > >                - Nicholas Paldino [.NET MVP]



> > > > Hi

> > > > please can you tell me what I need to define in my file...

> > > > Using System;
> > > > Using System.Drawing;
> > > > .
> > > > .
> > > > .

> > > > #define Number

> > > > namespace Bobby
> > > > {
> > > > }

> > > > I have tried defining with a value anmd without, with semi-colon and
> > > > without......

> > > > Thanks in advance



Wed, 03 Nov 2004 09:37:54 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. Preprocessor: defining a macro inside a #define directive

2. How to define preprocessor defines at workspace scope

3. #define defining other #defines

4. Preprocessor Q: conditional comparison when the symbol is undefined

5. #define token in string constant?

6. stringizing a #define token

7. Detecting macro defined as empty (as opposed to zero or undefined)

8. multiple #define and #undefine (newbie)

9. Defined or undefined behaviour?

10. Unexpected C2079 -- undefined struct -- but is defined!

11. Defined but undefined

12. #define SQRT(x) : C preprocessor computes square root

 

 
Powered by phpBB® Forum Software