Re: pack in structure or not?

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

 



On 7/23/06, Paul Drynoff <pauldrynoff@xxxxxxxxx> wrote:
But let's look how it looks like:
struct foo_arg args = {
  .arg1 = arg1,
  .arg2 = arg2,
...
};
<--- we occupy stack space here
Agree. But we do the same when the arguments are passed by value as
well (although not on the caller's stack)

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
}
Only if arg2 has to be dynamically calculated inside the callee.


>But I don't think it increases the clarity if you pack up all function
>arguments that have more then 2 values.

lets `foo' looks like:
void foo(int par1, int par2, int par3, int par4, int par5);

if we call it like this
foo(a + b, (c + d) << e, ...);
it is rather complex understand what's going on, but
if argX depended on argY's evaluation, you might end up with very
difficult to debug bugs in different architectures / compilers I
think. The order of argument evaluation is dependent on the compiler
(I am not sure about same compiler on different archs. though)

struct foo_args args = {
 .par1 = a + b,
 .par2 = (c + d) << e,
};
foo(&args);

this code looks more clear for me.
To me, too. And mostly for many :-)

Regards,
Om.

--
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