linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Issue "address of local variable returned"
@ 2005-05-25  7:27 Amit Dang
       [not found] ` <2ab8d39a05052610175e3d7018@mail.gmail.com>
  2005-05-27 16:09 ` Glynn Clements
  0 siblings, 2 replies; 4+ messages in thread
From: Amit Dang @ 2005-05-25  7:27 UTC (permalink / raw)
  To: linux-c-programming

Hi All,
    I am facing following issue
(g++ compiler  "g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)" is being
used for compilation.)

Following piece of code gives warning: "address of local variable `op'
returned"
#################################
#include<iostream>
using namespace std;

struct s {
    char op[24];
    int j;
};

char* fun()
{
    struct s op;
    strcpy(op.op, "898898898\0");
    return op.op;
}

int main()
{
    cout << fun() << endl;
    return 0;
}
#################################
But when the structure is change no warning is issued
Following is the new structure
#################################
struct s {
        int j;
        char op[24];
};
#################################

Obviously I know that "op.op" should not be returned.

g++ compiler  "g++ (GCC) 3.2.3 20030502 (Red Hat Linux 3.2.3-20)" is being
used for compilation.

Thanks in advance,
Amit Dang


^ permalink raw reply	[flat|nested] 4+ messages in thread
* Issue "address of local variable returned"
@ 2005-05-25  7:17 Amit Dang
  0 siblings, 0 replies; 4+ messages in thread
From: Amit Dang @ 2005-05-25  7:17 UTC (permalink / raw)
  To: linux-c-programming

Hi All,
    I am facing following issue

Following piece of code gives warning: "address of local variable `op'
returned"
#################################
#include<iostream>
using namespace std;

struct s {
    char op[24];
    int j;
};

char* fun()
{
    struct s op;
    strcpy(op.op, "898898898\0");
    return op.op;
}

int main()
{
    cout << fun() << endl;
    return 0;
}
#################################
But when the structure is change no warning is issued
Following is the new structure
#################################
struct s {
        int j;
        char op[24];
};
#################################

Obviously I know that "op.op" should not be returned.

Thanks in advance,
Amit Dang


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-27 16:09 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-05-25  7:27 Issue "address of local variable returned" Amit Dang
     [not found] ` <2ab8d39a05052610175e3d7018@mail.gmail.com>
2005-05-27  3:54   ` Amit Dang
2005-05-27 16:09 ` Glynn Clements
  -- strict thread matches above, loose matches on Subject: below --
2005-05-25  7:17 Amit Dang

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).