473,385 Members | 1,930 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,385 software developers and data experts.

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 3112
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******@myrapidsys.com (remove the x to send email)
http://www.geocities.com/abowers822/

Nov 14 '05 #3
jt
Thank you!
JT

"Al Bowers" <ab*****@myrapidsys.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*****@myrapidsys.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******@myrapidsys.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:130557 sci.energy.hydrogen:80505 sci.environment:395335
Newsgroups: sci.energy.hydrogen,sci.energy,alt.energy,sci.envi ronment,alt.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********@news.boeing.com>
X-Mimeole: Produced By Microsoft MimeOLE V6.00.2800.1409
X-Priority: 3
X-Msmail-Priority: Normal
Lines: 31
Sender: nn**@news.boeing.com (Boeing NNTP News Access)
Organization: The Boeing Company
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
References: <11**********************@o13g2000cwo.googlegroups .com> <wq********************@adelphia.com> <11*********************@z14g2000cwz.googlegroups. com> <1%***************@news20.bellglobal.com> <11**********************@f14g2000cwb.googlegroups .com> <42**************@lut.fi> <Rq********************@news20.bellglobal.com> <11**********************@g49g2000cwa.googlegroups .com> <3e************@individual.net> <11**********************@g43g2000cwa.googlegroups .com> <3ep2v4F463f2U1
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*****@enteract.com> wrote in message
news:uq*************@newssvr12.news.prodigy.com... 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
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
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='...
8
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 -------------------------------------------------------------------------------- ...
13
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...
38
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...
22
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...
1
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...
5
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...
1
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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...

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.