/bitfield/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/bitfield/trunk

« back to all changes in this revision

Viewing changes to src/c_main.c

  • Committer: Gustav Hartvigsson
  • Date: 2020-11-03 21:37:26 UTC
  • Revision ID: gustav.hartvigsson@gmail.com-20201103213726-cnc5g98qp233eio6
* removed unused code
* Added a bit of information on how to use this to the comments

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdio.h>
 
2
#include <glib.h>
 
3
#include "vbitfield.h"
 
4
 
 
5
enum {
 
6
  FOO_A,
 
7
  FOO_B,
 
8
  FOO_C,
 
9
  FOO_LEN
 
10
};
 
11
 
 
12
int
 
13
main (int argc, char ** argv) {
 
14
  bit_field_init ();
 
15
  
 
16
  BitFieldInfo info[] = {
 
17
    {FOO_A, 0, 5, 6},
 
18
    {FOO_B, 6, 7, 2},
 
19
    {FOO_C, 8, 15, 8},
 
20
  };
 
21
 
 
22
  if (bit_field_add_type ("foo", info, FOO_LEN)) {
 
23
    fprintf (stdout, "Something went wrong when adding info.\n");
 
24
  }
 
25
 
 
26
  guint16 t1 = 0;
 
27
  bit_field_set (&t1, "foo", FOO_C, 137);
 
28
  fprintf (stdout, "%i\n", t1);
 
29
  bit_field_set (&t1, "foo", FOO_B, 3);
 
30
  fprintf (stdout, "%i\n", t1);
 
31
  bit_field_set (&t1, "foo", FOO_A, 7);
 
32
  fprintf (stdout, "%i\n", t1);
 
33
 
 
34
  guint16 t2 = bit_field_get (t1, "foo", FOO_C);
 
35
  fprintf (stdout, "C: %i\n", t2);
 
36
  t2 = bit_field_get (t1, "foo", FOO_B);
 
37
  fprintf (stdout, "B: %i\n", t2);
 
38
  t2 = bit_field_get (t1, "foo", FOO_A);
 
39
  fprintf (stdout, "A: %i\n", t2);
 
40
 
 
41
  bit_field_deinit ();
 
42
 
 
43
  return 0;
 
44
}