Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why assign variable to itself [duplicate]

Tags:

c

A co-worker wrote a function like this (the comment was written by me):

static void foo(void *arg)
{
    //arg is NOT global variable
    arg = arg;
    // call other function, but doesn't use arg
    foo2();
}

Is there some reason to write code like this? Does it have some special purpose?

like image 517
How Chen Avatar asked Oct 24 '13 08:10

How Chen


1 Answers

This is just one way of suppressing a compiler warning for an unused argument.

Other common methods are:

(void)arg;

or

#pragma unused (arg)    // not supported by all compilers
like image 170
Paul R Avatar answered Oct 07 '22 07:10

Paul R