Skip to content

Arduino.h Defines Macros that Should be Functions #551

Closed as not planned
Closed as not planned
@moefrumkin

Description

@moefrumkin

#define min(a,b) ((a)<(b)?(a):(b))

This macro and those that follow will lead to unexpected behavior if certain expressions are passed into it. For example,

    int x = 0, y = 1;
    
    printf("Min is: %d", min(++x, ++y));

Will print 2 instead of 1 since the expansion gives the expression ((++x)<(++y)?(++x):(++y)). Is there a reason this shouldn't be a function?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions