473,395 Members | 1,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

xdr library

Hi,

I'm getting the error:

error: invalid lvalue in unary `&'

from lines '//*' when compiling:
-----------------------
#include <stdio.h>
#include <string.h>
#include <rpc/rpc.h>

int f(void)
{
int x,y,s;
FILE *outfile;
XDR xdrs;
char filename[]="\0";

lba_MakeFilename(filename,"chkpt","xdr",nt);
outfile = fopen(filename, "w");
//Set up an XDR stream
xdrstdio_create(&xdrs, outfile, XDR_DECODE);

for(x=1; x<=(par->nx); x++) {
for(y=1; y<=(par->ny); y++) {
for(s=0; s<nvecs; s++) {
xdr_float(&xdrs, &((float)N[x][y].n_r[s])); //*
xdr_float(&xdrs, &((float)N[x][y].n_b[s])); //*
xdr_float(&xdrs, &((float)N[x][y].n_s[s])); //*
}
for(s=0; s<dim; s++) {
xdr_float(&xdrs, &((float)N[x][y].d[s])); //*
}
xdr_int(&xdrs, &(N[x][y].wall_state));
}
}
}
xdr_destroy(&xdrs);
fclose(outfile);
return 0;
}
------------------
where in my code I also #include'd header files defining relevant vars
and functions.

I've used this construct before in another code of mine without probs.

Any clues?

Many thanks!
Neil.

Nov 14 '05 #1
6 3988
he*******@hotmail.com wrote:
Hi,

I'm getting the error:

error: invalid lvalue in unary `&'

from lines '//*' when compiling:

[ ... ]
xdr_float(&xdrs, &((float)N[x][y].n_r[s])); //*
The address operator can only be applied to lvalues. A cast expression is
not an lvalue. Therefore you cannot take the address of the expression
(float) N[x][y].n_r[s].
I've used this construct before in another code of mine without probs.


The compiler was probably not invoked in standard conforming mode.
Christian

Nov 14 '05 #2

heyerd...@hotmail.com wrote:
Hi,

I'm getting the error:

error: invalid lvalue in unary `&'

from lines '//*' when compiling:
-----------------------
xdr_float(&xdrs, &((float)N[x][y].n_r[s])); //*


try this, xdr_float(&xdrs, (float *) &(N[x][y].n_r[s]));

Nov 14 '05 #3
Thanks very much!

Nov 14 '05 #4
Thanks very much!

Nov 14 '05 #5
ma*******@gmail.com writes:
heyerd...@hotmail.com wrote:
Hi,

I'm getting the error:

error: invalid lvalue in unary `&'

from lines '//*' when compiling:
-----------------------
xdr_float(&xdrs, &((float)N[x][y].n_r[s])); //*


try this, xdr_float(&xdrs, (float *) &(N[x][y].n_r[s]));


That doesn't do the same thing. The original version converts the
value of N[x][y].n_r[s] to type float. I don't know what the type of
N[x][y].n_r[s] is, but if it's an arithmetic type, the cast does an
arithmetic conversion, which should preserve the value (possibly with
some loss of precision). The expression is illegal because the result
of a cast is not an lvalue, and therefore doesn't have an address.
<OT>I think a cast result is an lvalue in C++.</OT>

The modified version takes the address of N[x][y].n_r[s] and converts
that address to type float*. That's a pointer conversion, not a
numeric conversion. If N[x][y].n_r[s] is already of type float, then
both casts are unnecessary. If it's of type double, for example, then
the pointer conversion will result in the bits being interpreted as if
they were of type float. For example, if double is 64 bits and float
is 32 bits, this will cause the first 32 bits of the double object to
be interpreted as a float, which most likely will give you complete
garbage.

If N[x][y].n_r[s] is not of type float, and you need the address of a
float object with the value of N[x][y].n_r[s], you need to create
a temporary object:

float tmp = N[x][y].n_r[s];
...
xdr_float(&xdrs, &tmp);

If N[x][y].n_r[s] is of type float, just drop the cast.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Nov 14 '05 #6
Keith Thompson wrote:
The expression is illegal because the result
of a cast is not an lvalue, and therefore doesn't have an address.
<OT>I think a cast result is an lvalue in C++.</OT>


<OT>No, it's not.</OT>
Christian
Nov 14 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: pieter.breed | last post by:
Hi All, The company I work for has traditionally used COM/ActiveX for the solutions that it provides. We are in the process of moving to .NET and a few applications have been written in VB.NET...
3
by: K.S.Liang | last post by:
Hi all, 1> If there are more than one dynamic linking libraries in the file system, how do I know which one is loaded into system? Any C library or system call can tell me which *.so or *.sl is...
1
by: Jim | last post by:
Have fully operational software package developed on VB.NET that worked until Jan 1 2003, with early stage deployments on Oct 10, Oct 23, Nov 11, Dec 12 and Dec 30. When attempted final...
10
by: mwt | last post by:
So in a further attempt to learn some Python, I've taken the little Library program (http://groups.google.com/group/comp.lang.python/browse_thread/thread/f6a9ccf1bc136f84) I wrote and added...
10
by: Julian | last post by:
I get the following error when i try to link a fortran library to a c++ code in .NET 2005. LINK : fatal error LNK1104: cannot open file 'libc.lib' the code was working fine when built using...
20
by: Frank-O | last post by:
Hi , Recently I have been commited to the task of "translating" some complex statistical algorithms from Matlab to C++. The goal is to be three times as fast as matlab ( the latest) . I've...
6
by: =?Utf-8?B?WW9naSBXYXRjaGVy?= | last post by:
Hello, I am using Visual Studio-2003. I created a project to build my library. Since I am using third party libraries as well, I have specified those additional library dependencies in project...
0
by: JosAH | last post by:
Greetings, the last two article parts described the design and implementation of the text Processor which spoonfeeds paragraphs of text to the LibraryBuilder. The latter object organizes, cleans...
0
by: JosAH | last post by:
Greetings, welcome back; above we discussed the peripherals of the Library class: loading and saving such an instantiation of it, the BookMark interface and then some. This part of the article...
16
by: Xiaoxiao | last post by:
Hi, I got a C library, is there a way to view the public function names in this library so that I can use in my C program? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.