Re: pack in structure or not?

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

On Sun, Jul 23, 2006 at 07:50:51PM +0400, Paul Drynoff wrote:
> But let's look how it looks like:
> struct foo_arg args = {
>   .arg1 = arg1,
>   .arg2 = arg2,
> ...
> };
> <--- we occupy stack space here
> 
> foo(&args);
> 
> void foo(struct foo_arg *args)
> {
>   args->arg1 <--- we used pointer so we it slower then just
>   arg1
> 
> //often used argument
>   arg2 = args->arg2<-- we occupy stack space twice
> }

Hm well. In this situation I think its rather bad.

> if we call it like this
> foo(a + b, (c + d) << e, ...);
> it is rather complex understand what's going on, but
> struct foo_args args = {
>  .par1 = a + b,
>  .par2 = (c + d) << e,
> };
> foo(&args);
> 
> this code looks more clear for me.

I would prefer the direct call. But what about single value parameters?

parm1 = a + b;
parm2 = (c + d) << e;
foo(parm1, parm2);

Ok even then.. a direct call would look way nicer.

Another point is, if your function takes more then 5 parameters you
should probably reconsider your design.

Hannes

--
Kernelnewbies: Help each other learn about the Linux kernel.
Archive:       http://mail.nl.linux.org/kernelnewbies/
FAQ:           http://kernelnewbies.org/faq/


[Index of Archives]     [Newbies FAQ]     [Linux Kernel Mentors]     [Linux Kernel Development]     [IETF Annouce]     [Git]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux SCSI]     [Linux ACPI]
  Powered by Linux