wrote:
> Hello,
> Followed here is a simplified code example of something which I
> try to implement; in essence , I want to assign a value to a return
> value of a method is C.
It is possible in C++ to use the value returned by a function call as
the left operand of an assignment operator; this is not possible in
C.
So, are you programming in C or in C++? Your use of the term "method"
makes me think you're using C++ - neither language actually uses the
term "method", but it is in common use to describe what C++ call
member functions; something that doesn't exist in C.
C and and C++ are two significantly different languages. If your
question is actually about C++, then this is the wrong newsgroup. You
should go to comp.lang.c++. There will be a much larger number of
people there who are competent to answer your question.
> ... I know, of course, that in this example I
> can
> get this by newskb->iph = iphdr (this also appears in a commented
> line in the example below) ; but I want to achieve the same where
> the left side is : ip_hdr(newskb). Alas, if I try this , I get
> a compilation error about line 25.
> line 25 is:
> ip_hdr(newskb)=iphdr;
> the error I get is:
> lval.c:25: error: invalid lvalue in assignment
> I use gcc-4.1.2-33c, and I compile without any flag.
>
> I tried casting,
> like : (struct iphdr*)ip_hdr(newskb)=iphdr;
> or like:
> ip_hdr(newskb)=(struct iphdr*)iphdr;
> and got the same error.
> Any ideas?
Yes - I've got the idea that you have no concept of the kind of
information that is needed to answer your question. You should provide
the following information:
What is the definition of ip_hdr()? How is it related to iphdr? What
is newskb? And what in the world are you actually trying to do?
If you are writing in C++, the existence of a "struct iphdr"
declaration somewhere in your code makes "iphdr" a type name. In all
three statements you've provided, the final use of 'iphdr' is in a
context where a type name is not allowed. This makes it very unclear
what it is that you're actually trying to do. If you're writing in C,
iphdr is not necessarily a type name - you're allowed to define a
variable with the same name, but it's not a good idea to actually do
so.
I would strongly recommend creating a complete program, as small as
possible, that actually demonstrates what it is that you're trying to
do. Compile it, and then post the COMPLETE TEXT of the program, and
the COMPLETE TEXT of the compiler's error messages. Please make sure
that you post it to the appropriate newsgroup.