473,785 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help, getting compiler error warning on returning a temporary character string

jt
I'm getting a compiler error: warning C4172: returning address of local
variable or temporary

Here is the function that I have giving this error: I'm returning a
temporary char string and its not liking it.
How can I fix this?

char *dequeue(struct node **first)
{
char temp[1024];
struct node *p=*first;
if(*first==NULL )
{
printf("\nqueue is empty\n");
return(0);
}
else
{
p=*first;
*first=(*first)->next;
strcpy(temp,p->data);
free(p);
return(temp); <----------------- compiler is not liking this
}
}

Big thanks!
JT
Nov 14 '05 #1
4 3153
jt wrote:

I'm getting a compiler error:
warning C4172: returning address of local
variable or temporary

Here is the function that I have giving this error: I'm returning a
temporary char string and its not liking it.
How can I fix this?

char *dequeue(struct node **first)
{
char temp[1024]; return(temp); <----------------- compiler is not liking this
}
}

char *dequeue(struct node **first)
{
static char temp[1024];
return temp;
}

void dequeue(struct node **first, char *temp)
{

}

--
pete
Nov 14 '05 #2


jt wrote:
I'm getting a compiler error: warning C4172: returning address of local
variable or temporary

Here is the function that I have giving this error: I'm returning a
temporary char string and its not liking it.
How can I fix this?

char *dequeue(struct node **first)
{
char temp[1024];
struct node *p=*first;
if(*first==NULL )
{
printf("\nqueue is empty\n");
return(0);
}
else
{
p=*first;
*first=(*first)->next;
strcpy(temp,p->data);
free(p);
return(temp); <----------------- compiler is not liking this
}
}


Yes, storage for the char array ceases when the function
returns. Your compiler is informing you that the return
value is of no value.

A quick fix would be use of the 'static' keyword. Change
the declaration of the char array to:

static char temp[1024];
--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #3
jt
Thank you!
JT

"Al Bowers" <ab*****@myrapi dsys.com> wrote in message
news:3e******** ****@individual .net...


jt wrote:
I'm getting a compiler error: warning C4172: returning address of local
variable or temporary

Here is the function that I have giving this error: I'm returning a
temporary char string and its not liking it.
How can I fix this?

char *dequeue(struct node **first)
{
char temp[1024];
struct node *p=*first;
if(*first==NULL )
{
printf("\nqueue is empty\n");
return(0);
}
else
{
p=*first;
*first=(*first)->next;
strcpy(temp,p->data);
free(p);
return(temp); <----------------- compiler is not liking this
}
}


Yes, storage for the char array ceases when the function
returns. Your compiler is informing you that the return
value is of no value.

A quick fix would be use of the 'static' keyword. Change
the declaration of the char array to:

static char temp[1024];
--
Al Bowers
Tampa, Fl USA
mailto: xab*****@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #4


Al Bowers wrote:

jt wrote:
I'm getting a compiler error: warning C4172: returning address of local
variable or temporary

Here is the function that I have giving this error: I'm returning a
temporary char string and its not liking it.
How can I fix this?

char *dequeue(struct node **first)
{
char temp[1024];
struct node *p=*first;
if(*first==NULL )
{
printf("\nqueue is empty\n");
return(0);
}
else
{
p=*first;
*first=(*first)->next;
strcpy(temp,p->data);
free(p);
return(temp); <----------------- compiler is not liking this
}
}
Yes, storage for the char array ceases when the function
returns. Your compiler is informing you that the return
value is of no value.

A quick fix would be use of the 'static' keyword. Change
the declaration of the char array to:

static char temp[1024];

--
Al Bowers
Tampa, Fl USA
mailto: xa******@myrapi dsys.com (remove the x to send email)
http://www.geocities.com/abowers822/


But also be aware that a future call to dequeue() will clobber what is
stored there:
value1 = dequeue(...);
...
value2 = dequeue(...); /* Just clobbered what value1 points to */
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
#! rnews 2715
Xref: xyzzy sci.energy:1305 57 sci.energy.hydr ogen:80505 sci.environment :395335
Newsgroups: sci.energy.hydr ogen,sci.energy ,alt.energy,sci .environment,al t.politics
Path: xyzzy!nntp
From: "Fred McGalliard" <fr************ ********@boeing .com>
Subject: Re: The world's largest solar power station planned for Portugal
X-Nntp-Posting-Host: e056750.nw.nos. boeing.com
Message-ID: <IG********@new s.boeing.com>
X-Mimeole: Produced By Microsoft MimeOLE V6.00.2800.1409
X-Priority: 3
X-Msmail-Priority: Normal
Lines: 31
Sender: nn**@news.boein g.com (Boeing NNTP News Access)
Organization: The Boeing Company
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
References: <11************ **********@o13g 2000cwo.googleg roups.com> <wq************ ********@adelph ia.com> <11************ *********@z14g2 000cwz.googlegr oups.com> <1%************ ***@news20.bell global.com> <11************ **********@f14g 2000cwb.googleg roups.com> <42************ **@lut.fi> <Rq************ ********@news20 .bellglobal.com > <11************ **********@g49g 2000cwa.googleg roups.com> <3e************ @individual.net > <11************ **********@g43g 2000cwa.googleg roups.com> <3ep2v4F463f2 U1
Date: Mon, 16 May 2005 15:01:32 GMT

I want you both to step back a bit and look at Don't claim more carefully. I
think it is interesting, and very jingoistic, Something a politician would
say at an oil rally, but not as meaningful on close examine. There is no
question (I think) that some of our panels are making net watt-hours today
in a strict energy accounting. It is Don's burden that changes this, and his
odd accounting structure that assures the claim cannot be falsified. But it
is just this that makes it both interesting, and useless for making our long
term energy decisions.
I think we need to examine what "burden" our PV solar structure should carry
and why before we can safely jump on, or off, the bandwagon.

"fkasner" <fk*****@entera ct.com> wrote in message
news:uq******** *****@newssvr12 .news.prodigy.c om... BobG wrote:
Boy, you are tough Don. The way I read that mantra you keep
repeating.."not one net watthour... has ever been produced" means that
a pv panel from the 70s, sitting in the sun, hasn't reached break even
in 35 years? Way unlikely. Only takes one panel to hit break even and I
have disproven your claim. Time is on my side. (Mick Jagger, 1965).


The key to his claim is the usually well hidden costs for collateral
expenses in producing that PV panel and for things that are usually left
out that are after manufacture costs such as synchronous inverters if
you (as is true in most cases) AC rather than low voltage DC.

I don't think he really exaggerates at all.

FK

Nov 14 '05 #5

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

Similar topics

4
1760
by: hrmadhu | last post by:
Hi, I wish to declare a vector of deque of int, which I do as follows. #include<vector> #include<deque> #include<iostream> using namespace std; int main(int argc, char* argv) {
5
2149
by: xuatla | last post by:
Hi, I encountered the following compile error of c++ and hope to get your help. test2.cpp: In member function `CTest CTest::operator+=(CTest&)': test2.cpp:79: error: no match for 'operator=' in '*this = CTest::operator+(CTest&)((+t2))' test2.cpp:49: error: candidates are: CTest CTest::operator=(CTest&) make: *** Error 1
8
5483
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
13
6218
by: webzila | last post by:
Hello, I have to write a program for an 8051 micro-controller using micro-C to monitor Switch 1 and if the switch in pushed the message "switch 1 pushed" should be displayed in the LCD. Also the microcontroller should display in the LCD the value of the voltage applied to the input of the ADC. The above procedure should only execute once the user has entered "1234" using a keypad that is attached to the 8051 microprocessor.
38
2557
by: Red Dragon | last post by:
I am self study C student. I got stuck in the program below on quadratic equation and will be most grateful if someone could help me to unravel the mystery. Why does the computer refuse to execute my scanf ("%c",&q); On input 3 4 1 (for a,b and c) I had real roots OK On input 1 8 16 I had same real roots OK. However on 4 2 5, (for imaginary roots ) the computer cannot see the scanf ("%c",&q); statement. It just jumps...
22
2336
by: Mike Polinske | last post by:
I am new to the C programming language but have been programming in Cobol for over 10 years. When I compile the following code, it compiles clean but I get an application error both under Windows XP and Win2K. #include <stdio.h> #include <ctype.h> char title = "Year End Report";
1
4129
by: keithb | last post by:
This application works without error in the development environment using the VS web server. When I publish the site to my IIS 6.0 server, I get this error at runtime when I open the Change Password page: Compiler Error Message: CS0030: Cannot convert type 'ASP.admin_changepassword_aspx' to 'System.Web.UI.WebControls.ChangePassword' Compiler Error Message: CS0030: Cannot convert type
5
1846
by: Kelth.Raptor | last post by:
Im having some difficulty with strings here, I hope someone is kind enough to help, I do appreciate it. Im working on a grade point average calculator for my intro to programming class and I thought I would go a bit above and beyond the scope of the class and use strings. But I ran into a snag with my getgrades function. The compiler gives me the error: "81 ISO C++ forbids comparison between pointer and integer" here is the code for the...
1
2070
by: JavaNme | last post by:
I need someone to debug the following errors for me, so that i can run the program. 1>------ Build started: Project: TheBankProject, Configuration: Debug Win32 ------ 1>Compiling... 1>BANK.cpp 1>c:\documents and settings\alan\my documents\visual studio 2005\projects\thebankproject\bank.cpp(161) : error C2043: illegal break 1>c:\documents and settings\alan\my documents\visual studio 2005\projects\thebankproject\bank.cpp(188) : error C2043:...
0
9646
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9483
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10346
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...
1
10096
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,...
0
9956
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8982
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7504
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
5514
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3658
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.