---
name: "rflag"
section: "3"
platform: "linux"
package: "libroy-dev"
version: "1.0.8-1"
release: "Debian 3.1 (Sarge)"
platforms: ["linux"]
url: "https://new.carta.tech/rflag"
---

# rflag(3)

bit flag routines

## NAME

rflag - bit flag routines

## SYNOPSIS

\#include \<roy.h\>

RFLAG\_FLAGS (struct);

RFLAG\_SET (struct, flag);

RFLAG\_UNSET (struct, flag);

RFLAG\_ISSET (struct, flag);

RFLAG\_ONLYSET (struct, flag);

## DESCRIPTION

These are a set of macros for setting, clearing and checking bit flags as found in a number of structures.  In order for this to work, the structure must have a 'flags' member, for which you create an enumerated list of bit flags.

*RFLAG\_FLAGS*(3) returns the struct-\>flags member.

*RFLAG\_SET*(3) sets the value of *flag* in the flags member in *struct*. This is done using the bitwise & operator.

*RFLAG\_UNSET*(3) clears the value of *flag* in the flags member in *struct*.

*RFLAG\_ISSET*(3) returns the TRUE if the flag *flag* is set, or FALSE if unset.

*RFLAG\_ONLYSET*(3) returns TRUE if *flag* is the only bit turned on in the flags member of *struct*.

## MACROS

These calls are all implemented with macros.

## EXAMPLE

/\* Create an enumerated list of flags. \*/

typedef enum {\
     FOO\_NEEDS\_BAR = 1 \<\< 0,\
     FOO\_NEEDS\_BAZ = 1 \<\< 1,\
     FOO\_NEEDS\_BAX = 1 \<\< 2 } MyFlags;

/\* Create a structure with a flags member. \*/

typedef struct {\
     /\* ... \*/\
     unsigned int flags;\
     /\* ... \*/ } MyStruct;

/\* Example setting/checking. \*/

void foo (void) {\
     MyStruct \*mys;

```
    /* ... */
```

```
    RFLAG_SET (mys, FOO_NEEDS_BAR);
```

```
    if (RFLAG_ISSET (mys, FOO_NEEDS_BAZ)) {
        /* do something.. */
    }
```

```
    RFLAG_UNSET (mys, FOO_NEEDS_BAR);
}
```

## SEE ALSO

[*roy*(3)](/roy/3.md)
