[R-pkg-devel] warning: explicit assigning values of variable of type ....

Vladimir Dergachev vo|ody@ @end|ng |rom m|nd@pr|ng@com
Fri Jun 7 12:49:41 CEST 2024



On Thu, 6 Jun 2024, Iris Simmons wrote:

> Unless I'm misunderstanding, you're trying to pass a value by name to a
> function. That is not a thing in C nor C++. However if you want to name the
> arguments, you can do so with comments:
>
> /* print = */ print

I would recommend against using comments in this fashion because while it 
tells you what you meant to do, the compiler does not know it. If you made 
an error the comment will make it harder to find.

If you happen to have a function with a lot of arguments of similar types 
and putting arguments in order is a concern, you can instead convert them 
to a struct and pass a struct instead:

typedef struct {
          int a;
          int b;
          } INPUT_TYPE1

void myfunc(INPUT_TYPE1 x);

And somewhere:
{
INPUT_TYPE1 x;

x.a=3;
x.b=4;

myfunc(x);
}

I don't know whether the modern compilers are smart enough to optimize 
this in the same way as passing an argument list. If this is a concern, 
probably some code restructuring is a good idea.

best

Vladimir Dergachev

>
> On Thu, Jun 6, 2024, 19:16 Søren Højsgaard via R-package-devel <
> r-package-devel using r-project.org> wrote:
>
>> Dear all,
>>
>> From CRAN maintainers I recieve:
>>
>>
>> Flavor: r-devel-linux-x86_64-debian-gcc
>> Check: whether package can be installed, Result: WARNING
>>   Found the following significant warnings:
>>     grips_fit_ips.cpp:149:45: warning: explicitly assigning value of
>> variable of type 'int' to itself [-Wself-assign]
>>     grips_fit_ips.cpp:213:16: warning: explicitly assigning value of
>> variable of type 'int' to itself [-Wself-assign]
>>     grips_fit_ips.cpp:254:10: warning: explicitly assigning value of
>> variable of type 'int' to itself [-Wself-assign]
>>     grips_fit_ips.cpp:254:21: warning: explicitly assigning value of
>> variable of type 'double' to itself [-Wself-assign]
>>
>>
>>
>> The first warning pertains to the line:
>>
>>     conips_inner_(S, K, elst0, clist0, print=print);
>>
>> print on lhs of "=" is the formal name and print on rhs of "=" the name of
>> a variable. Does the compiler think I assign an integer
>> to itself? Like if I write
>>
>> int a=7;
>> a=a;
>>
>> Can anyone help me throw light on this?
>>
>> Thanks in advance
>> Søren
>> ______________________________________________
>> R-package-devel using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-package-devel using r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>


More information about the R-package-devel mailing list