-1
static int ModifyStatus(struct LinkService* ar, const char* property, char* value, int len)
{
    (void)(ar);

    if (property == NULL || value == NULL) {
        return -1;
    }

    /* modify status property*/
    printf("Modify Receive property: %s(value=%s[%d])\n", property, value,len);
    if (strcmp(property,"CarControl") == 0) {
        g_car_control_mode = CAR_DIRECTION_CONTROL_MODE;
        car_direction_control_func(value);
    } else if (strcmp(property, "ModularControl") == 0) {
        g_car_control_mode = CAR_MODULE_CONTROL_MODE;
        car_modular_control_func(value);
    } else if (strcmp(property, "SpeedControl") == 0) {
        g_car_control_mode = CAR_SPEED_CONTROL_MODE;
        car_speed_control_func(value);
    } 

    /*
     * if Ok return 0,
     * Otherwise, any error, return StatusFailure
     */
    return 0;
}

I can't understand this stand for what when ar is a struct. Thanks very much. I consider it as a function point before. Thanks again.

张一帆
  • 1
  • 1
  • 2
    It "uses" `ar` and eliminates a compiler warning. You could get the same by changing the function definition to `static int ModifyStatus(struct LinkService* , const char* property, char* value, int len)` to tell the compiler ahead of time that we aren't using that parameter. – user4581301 Jun 17 '21 at 16:51
  • 3
    `ar` in your posted code is not a struct but a pointer. – MikeCAT Jun 17 '21 at 16:52
  • 5
    Please remove the *Also I want to know how does Histream app interact with hi3861 via wifi.* as that is a radically different topic. A question should ask only one question. – user4581301 Jun 17 '21 at 16:55
  • `ar` is a pointer not a struct. – Clifford Jun 17 '21 at 18:43

1 Answers1

6

The cast to (void) suppresses the compiler from warning that ar is unused. Sometimes, you may need a function to have a certain signature to conform to an interface, but not actually need to use all of the arguments. This is especially useful if your codebase uses -Werror.

Also see: How to suppress "unused parameter" warnings in C?

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
ollien
  • 4,418
  • 9
  • 35
  • 58