473,757 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Compilation and runtime error with vc++ Version 6.0

I narrowed down the source of the error. The stand-alone program
listed
below reproduces it. The compilation finishes but the warning is
too serious to ignore:

cl -GX prog.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

prog.cpp
prog.cpp(18) : warning C4172: returning address of local variable or
temporary
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:prog.exe
prog.obj

The line it refers to is in Matrix class definition:

const_reference operator()(size _type m, size_type n) const
{return array[m*ncol + n];}

The typedefs involved are
typedef double value_type;
typedef value_type& reference;
typedef const value_type& const_reference ;
typedef size_t size_type;
and array is of valarray type.

The array is a member of the Matrix class, so an element of it
should not be a temporary or a local variable, it seems to me.
Is this diagnostic correct? (Please see bottom of message for the
rest of the code.)

When I ran the program, the matrix it printed was
1 4.04
1 4.04
and the correct answer, given by the g++ compiled version, is
275 -495
275 -495

If anybody still has vc++ Version 6.0, I would appreciate
confirmation or denial that the compiler does what I said
above, by compiling and running the single-file program
below. It may be an installation or library problem I am
having. Should the standard library used by vc++ be updated
separately or do the patches issued by MS cover all there is
to cover (I have applied SP5 for Visual Studio)?

Thanks,
Levent

#include <iostream>
#include <cmath>
#include <valarray>

class Matrix
{
public:
typedef double value_type;
typedef value_type& reference;
typedef const value_type& const_reference ;
typedef size_t size_type;
Matrix() :nrow(0), ncol(0) {}
Matrix(size_typ e m, size_type n) : nrow(m), ncol(n)
{array.resize(m *n, 0);}
size_type rowsize() const {return nrow;}
size_type colsize() const {return ncol;}

reference operator()(size _type m, size_type n) {return array[m*ncol
+ n];}
const_reference operator()(size _type m, size_type n) const {return
array[m*ncol + n];}
std::valarray<v alue_type> array;
Matrix & operator=(const Matrix & B)
{
if (&B != this)
{
nrow = B.rowsize();
ncol = B.colsize();
array.resize(nr ow*ncol);
array = B.array;
}
return *this;
}

friend void print(const Matrix& A)
{
size_t m, n;
for (m = 0; m < A.nrow; ++m)
{
for (n = 0; n < A.ncol; ++n)
std::cerr << " " << A(m, n);
std::cerr << '\n';
}
}

private:
size_type nrow, ncol;
};
Matrix operator*(const Matrix & A, const Matrix & B)
{
size_t m = A.rowsize(), p = A.colsize(), n = B.colsize(), i, j, k;
Matrix C(m, n);
for (i = 0; i < m; ++i)
for (j = 0; j < n; ++j)
for (k = 0; k < p; ++k)
C(i, j) += A(i, k)*B(k, j);
return C;
}

int main ()
{
Matrix M(2, 2);
Matrix N(2, 2), P(2, 2);
M.array = 275;
N(0, 0) = 1;
N(0, 1) = -2;
N(1, 0) = 0;
N(1, 1) = 1.0/5.0;
P = M*N;
print(P);
return 0;
}
Jul 19 '05 #1
1 3621
On 11 Nov 2003 17:48:06 -0800, lk**@earthlink. net (Count Dracula)
wrote:
I narrowed down the source of the error. The stand-alone program
listed
below reproduces it. The compilation finishes but the warning is
too serious to ignore:

cl -GX prog.cpp
Microsoft (R) 32-bit C/C++ Optimizing Compiler Version 12.00.8168 for
80x86
Copyright (C) Microsoft Corp 1984-1998. All rights reserved.

prog.cpp
prog.cpp(18) : warning C4172: returning address of local variable or
temporary
Microsoft (R) Incremental Linker Version 6.00.8447
Copyright (C) Microsoft Corp 1992-1998. All rights reserved.

/out:prog.exe
prog.obj

The line it refers to is in Matrix class definition:

const_reference operator()(size _type m, size_type n) const
{return array[m*ncol + n];}
Change that to:

value_type operator()(size _type m, size_type n) const
{return array[m*ncol + n];}
The typedefs involved are
typedef double value_type;
typedef value_type& reference;
typedef const value_type& const_reference ;
typedef size_t size_type;
and array is of valarray type.

The array is a member of the Matrix class, so an element of it
should not be a temporary or a local variable, it seems to me.


However, valarray::opera tor[] const returns a temporary object by
value. This is considered a defect in the standard:
http://std.dkuug.dk/jtc1/sc22/wg21/d...ctive.html#389

The change above is the only reasonable portable solution until the
defect goes through.

Tom
Jul 19 '05 #2

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

Similar topics

0
2078
by: Jason Jefferies | last post by:
I'm currently converting a number of applications written using the MFC in vc++ version 6 into a workable .NET solution. Just trying to build the apps in version 7 without worrying about optimising the solution has produced a number of compilation errors in the vc7 MFC classes. I know a lot of stuff is not usable in version 7 but cannot find a list of work arounds for a lot of it. For instance, this structure appears in WinSock.h as...
1
1565
by: Paljo | last post by:
Trying to compile VC++ 6 project in VC++ 7 and getting a compiling error, error C2955: '_com_ptr_t' : use of class template requires template argument list Any thoughts? Thanks
6
2224
by: Joachim | last post by:
I made some project changes (which seems it doesn't help if I undo) which have created compilation error: " Server Error in '/PCSWebApp1' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details
5
2951
by: Raterus | last post by:
I'm just throwing this error out for my sanity, I've seen posts about this, but never solutions. I'm using VS.NET 2003, Framework 1.1, and I'm getting a random error about every 1 out of 10 times I try to start to run/debug a project (through Visual Studio) Server Error in '/Intranet' Application. -------------------------------------------------------------------------------- Compilation Error Description: An error occurred during...
2
1953
by: VB Programmer | last post by:
I created a ASP.NET app locally and it works great. Uploaded it to my server and I get this error when trying to view a page. Any ideas? Server Error in '/earlyalert3' Application. ---------------------------------------------------------------------------- ---- Compilation Error
2
6938
by: Kevin R. | last post by:
I have been ignoring this problem for a few weeks now, but it's becoming a bit annoying not to mention unproductive. Here it goes: I compile my project with no errors. Then after I debug/run it, I get the runtime error noted at the end of this message. If I re-compile (without any changes) and re-run, then my project will run OK. This behavior is very consistent. Another words, the only way I can run an ASP.NET application is if I...
0
1216
by: z f | last post by:
i compile and test my vb.net asp.net web app. once in an hour or so i get a compilation error that only when i do IISRESET goes away. nothing related to my code. i compile and test on win XP pro+SP2 framework 1.1.4322 the error details: Microsoft (R) Visual Basic .NET Compiler version 7.10.6001.4 for Microsoft (R) .NET Framework version 1.1.4322.2032
1
5444
by: Arsalan Ahmad | last post by:
Hi all, I am trying to compile some source files using makefile. While compiling I am getting errors as shown below. Any idea how can I solve this problem. I believe I need to add some preprocessor directives but I dont know which one. Thanks, Arsalan
7
8453
by: Norman Diamond | last post by:
A project depends on VC runtime from Visual Studio 2005 SP1, and DotNet Framework 2. Options are set in the setup project properties, so if these two dependencies are not already installed then this installer will install them. But what about the situation where VC runtime has already been installed? In fact it's been installed twice. Although the project was built on a Windows XP system with Visual Studio 2005 SP1 and the results were...
0
10069
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9904
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9884
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7285
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5168
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5324
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3828
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
3395
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2697
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.