0

In my application i want to represent AND as 1 , and OR as 0, instead of opting for #define method , i am using enum to represent them , as shown in the below example program

#include <stdio.h>

enum gateConnection_t
{AND,OR}
gateConnection;

int main()
{

bool and_t = AND;
bool or_t = OR;

printf("%d\n",and_t);
printf("%d\n",or_t);

return 0;
}

As seen above , i am directly assigning the enum values to boolean vvariables. The program works as expected and my only question is whether the internal cast done is safe , or is it better to use explicit casting such as static_cast ?

2
  • What's the point of this? Commented Jun 11, 2013 at 13:34
  • @mwerschy c++ , sorry for tagging C Commented Jun 11, 2013 at 13:37

2 Answers 2

3

For starters, your {AND,OR} are the wrong way round.

Enums by standard start at 0 (although you can override that).

Use

enum gateConnection_t
{OR,AND}

instead.

The cast is safe by the way.

Conceptually though it's a nasty thing to do. Why do you want this; particularly in C++? What's wrong with true and false?

Sign up to request clarification or add additional context in comments.

1 Comment

yes , it was intended as an enum with AND = 0....I have to do this to represent relationship between two signals , the decision to use 1 and 0 is abitrary , with no particular reason
1
enum gateConnection_t
{AND=1,OR=0}
gateConnection;

or

enum gateConnection_t
{
OR=0,
AND  //<== this equal to the previous plus one automatically 
}gateConnection;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.