* functions returning structs: is it perfectly legal and how efficient?
@ 2009-02-20 9:15 Giacomo
2009-02-20 11:00 ` Jan Engelhardt
0 siblings, 1 reply; 2+ messages in thread
From: Giacomo @ 2009-02-20 9:15 UTC (permalink / raw)
To: netfilter-devel
Good morning.
Suppose we have a very little data structure - in kernel space - :
typedef struct
{
__u32 saddr, daddr;
__u16 sport, dport;
short int valid;
} net_quadruplet;
net_quadruplet get_quad_from_skb(const struct sk_buff* skb)
{
net_quadruplet netquad;
memset(&netquad, 0, sizeof(net_quadruplet));
netquad.valid = 1;
...
return netquad;
}
Is it perfectly legal?
Would it be more efficient
int get_quad_from_skb(const struct sk_buff* skb, net_quadruplet* nquad)
{
int return_value = 0;
/* modify nquad
.....
*/
return return_value;
}
?
Thank you very much for your attention.
Giacomo
--
Giacomo S.
http://www.giacomos.it
- - - - - - - - - - - - - - - - - - - - - -
* Aprile 2008: iqfire-wall, un progetto
open source che implementa un
filtro di pacchetti di rete per Linux,
e` disponibile per il download qui:
http://sourceforge.net/projects/ipfire-wall
* Informazioni e pagina web ufficiale:
http://www.giacomos.it/iqfire/index.html
- - - - - - - - - - - - - - - - - - - - - -
. '' `.
: :' :
`. ` '
`- Debian GNU/Linux -- The power of freedom
http://www.debian.org
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: functions returning structs: is it perfectly legal and how efficient?
2009-02-20 9:15 functions returning structs: is it perfectly legal and how efficient? Giacomo
@ 2009-02-20 11:00 ` Jan Engelhardt
0 siblings, 0 replies; 2+ messages in thread
From: Jan Engelhardt @ 2009-02-20 11:00 UTC (permalink / raw)
To: Giacomo; +Cc: netfilter-devel
On Friday 2009-02-20 10:15, Giacomo wrote:
>
>Suppose we have a very little data structure - in kernel space - :
>
>typedef struct
>{
> __u32 saddr, daddr;
> __u16 sport, dport;
> short int valid;
>} net_quadruplet;
Phew - http://www.kroah.com/linux/talks/ols_2002_kernel_codingstyle_talk/html/
>[case 1]:
>net_quadruplet get_quad_from_skb(const struct sk_buff* skb)
>{
> net_quadruplet netquad;
> memset(&netquad, 0, sizeof(net_quadruplet));
> netquad.valid = 1;
> ...
> return netquad;
>}
>
>Is it perfectly legal?
That's a question for a C forum/channel, but yes, it is valid.
>[code 2]:
>Would it be more efficient
>
>int get_quad_from_skb(const struct sk_buff* skb, net_quadruplet* nquad)
>{
> int return_value = 0;
> /* modify nquad
> .....
> */
> return return_value;
>}
>
>?
Depends on architecture and compiler. Usually it is said that the
compiler will transparently transform the first case into variant 2.
This need not always be the case however, returning an aggregate
object such as a struct could also be accomplished by filling
registers, where there are enough available to do so. This is all
highly implementation-dependent though.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2009-02-20 11:00 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-02-20 9:15 functions returning structs: is it perfectly legal and how efficient? Giacomo
2009-02-20 11:00 ` Jan Engelhardt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).