Arduino: struct pointer as function parameter

后端 未结 4 1257
我在风中等你
我在风中等你 2020-12-21 16:45

The code below gives the error:

sketch_jul05a:2: error: variable or field \'func\' declared void

So my question is: how can I pass a point

4条回答
  •  悲哀的现实
    2020-12-21 17:35

    This next code works for me as in Arduino 1.6.3:

    typedef struct S
    {
        int a;
    }S;
    
    void f(S * s, int v);
    
    
    
    void f(S * s, int v)
    {
        s->a = v;
    }
    
    void setup() {
    }
    
    void loop() {
        S anObject;
        // I hate global variables
    
        pinMode(13, OUTPUT);
        // I hate the "setup()" function
    
        f(&anObject, 0);
        // I love ADTs
    
        while (1) // I hate the "loop" mechanism
        {
            // do something
        }
    }
    

提交回复
热议问题