- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- Error in compiling C++
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2006 02:15 AM
тАО08-14-2006 02:15 AM
Codes:
#include
#include
using namespace std;
typedef struct
{
double a;
int b;
} AAA;
int main()
{
AAA *c, *v;
c->a = 1.1;
c->b = 2;
//*v = *c;
printf("TP\n");
//c->a = c->a*2;
printf("TP1\n");
cout << c->a << endl;
cout << c->b << endl;
printf("\n%d\n",&c->a);printf("%d\n",&v->a);
//cout << c << endl;
}
Solved! Go to Solution.
- Tags:
- SIGSEGV
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2006 02:21 AM
тАО08-14-2006 02:21 AM
SolutionBAD:
AAA *c;
Good:
AAA C,*c; /* declare both a struct and a pointer to struct*/
c = &C; /* Now set the pointer to the struct's address */
c->a = 1.1;
c->b = 2;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2006 02:32 AM
тАО08-14-2006 02:32 AM
Re: Error in compiling C++
Take into account that you have to allocate memory for them, a pointer is just a pointer.
Try this:
#include
#include
using namespace std;
typedef struct
{
double a;
int b;
} AAA;
int main()
{
AAA *c, *v;
c=new AAA;
v=new AAA;
c->a = 1.1;
c->b = 2;
//*v = *c;
printf("TP\n");
//c->a = c->a*2;
printf("TP1\n");
cout << c->a << endl;
cout << c->b << endl;
printf("\n%d\n",&c->a);printf("%d\n",&v->a);
//cout << c << endl;
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2006 03:11 AM
тАО08-14-2006 03:11 AM
Re: Error in compiling C++
c=new AAA;
would be enough, because after that you will point to the reserved area with the other v pointer.
It's really important working with C that you fully understand the difference between a pointer and the information it's pointing.
The pointer doesn't need to reserve memory, but you need to reserve memory for the data.
Once you have the data, of course you can point to that data so many pointers as you want without having to reserve more memory.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2006 03:38 AM
тАО08-14-2006 03:38 AM
Re: Error in compiling C++
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-14-2006 05:45 PM
тАО08-14-2006 05:45 PM
Re: Error in compiling C++
aCC6:
warning #2549-D: variable "c" is used before its value is set
c->a = 1.1;
^
warning #2549-D: variable "v" is used before its value is set
printf("%d\n",&v->a);
^
aCC3:
Warning 430: The variable 'v' is never initialized.
AAA *c, *v;
^
Warning 430: The variable 'c' is never initialized.
AAA *c, *v;
^
- Tags:
- uninitialized