Jump to content

Enum As Function Param Bug


Guest JoeB

Recommended Posts

When an enum type is used as a parameter to a function, then only that type should be allowed to be passed. The compiler does not type check the parameter and this is causing problems when porting code!

 

example:

 

typedef enum tagCAM
{
   CAM_A = 0,
   CAM_B,
   CAM_C,
}eCAMS;

void Foo( eCAMS cam )
{
  // do somthing with 'cam'
}


// Call:
Foo( CAM_A );   // OK
Foo( CAM_B );   // OK
Foo( 2 );       // BUG - Compiler should complain incompatible types.
Foo( 8 );       // What will the compiler do here? It doesn't complain!!!!

Link to post
Share on other sites
When an enum type is used as a parameter to a function, then only that type should be allowed to be passed. The compiler does not type check the parameter and this is causing problems when porting code!

 

example:

 

typedef enum tagCAM
{
   CAM_A = 0,
   CAM_B,
   CAM_C,
}eCAMS;

void Foo( eCAMS cam )
{
  // do somthing with 'cam'
}


// Call:
Foo( CAM_A );   // OK
Foo( CAM_B );   // OK
Foo( 2 );       // BUG - Compiler should complain incompatible types.
Foo( 8 );       // What will the compiler do here? It doesn't complain!!!!

 

 

I just tried this with the BoostC compiler

 

Foo( 2 ); Boostc gives as an error "arguments of function dont match parameters of call"

Foo( 8 ); Boostc gives the same error

Link to post
Share on other sites

True, I had missed the old function prototype that was:

 

void Foo( char cam );

 

instead of:

 

void Foo( eCAMS cam );

 

 

So this is still a bug, the compiler should tell me the function and prototype are different, and not compile. The code is unpredictable.

Link to post
Share on other sites

Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...