HPE GreenLake Administration
- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Pointer to arrays in g++
Operating System - HP-UX
1833016
Members
2161
Online
110048
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Forums
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
12-14-2004 07:33 AM
12-14-2004 07:33 AM
Good Morning:
I have function returning a pointer to array (must be the first element in the array) like this:
...
#define VAR_SIZE1 256
unsigned int var1[VAR_SIZE];
unsigned int *get_address(){return (unsigned int *)var1;}
...
I need to customize a caller program:
...
unsigned int var2[VAR_SIZE];
var2 = get_address();
But the compiler outputs this error:
incompatible types in assignment of `unsigned int*' to `unsigned int[256]'
Guys: If I can not return arrays, how I can redefine my function get_address(), or how I must declare var2 in the caller program?
Thanks in advance for your help.
I have function returning a pointer to array (must be the first element in the array) like this:
...
#define VAR_SIZE1 256
unsigned int var1[VAR_SIZE];
unsigned int *get_address(){return (unsigned int *)var1;}
...
I need to customize a caller program:
...
unsigned int var2[VAR_SIZE];
var2 = get_address();
But the compiler outputs this error:
incompatible types in assignment of `unsigned int*' to `unsigned int[256]'
Guys: If I can not return arrays, how I can redefine my function get_address(), or how I must declare var2 in the caller program?
Thanks in advance for your help.
alfonsoarias
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2004 07:49 AM
12-14-2004 07:49 AM
Solution
You need to change:
unsigned int var2[VAR_SIZE];
to:
unsigned int *var2;
var2 = get_address();
but note that eventhough var2 is a pointer, you can still use it like an array so that
var2[12] = 609;
is perfectly valid.
Also there is no need to cast the rurn value of your function since an array without a subscript is a pointer.
unsigned int *get_address(void)
{
return(var1);
} /* get_address */
is perfectly legal.
unsigned int var2[VAR_SIZE];
to:
unsigned int *var2;
var2 = get_address();
but note that eventhough var2 is a pointer, you can still use it like an array so that
var2[12] = 609;
is perfectly valid.
Also there is no need to cast the rurn value of your function since an array without a subscript is a pointer.
unsigned int *get_address(void)
{
return(var1);
} /* get_address */
is perfectly legal.
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2004 07:56 AM
12-14-2004 07:56 AM
Re: Pointer to arrays in g++
I suppose that I should add that there is really no reason for your function since once you change
unsigned int var2[VAR_SIZE];
to
unsigned int *var2;
then this assignment is perfectly legal (and more readable).
var2 = var1;
var2[0] = 12;
unsigned int var2[VAR_SIZE];
to
unsigned int *var2;
then this assignment is perfectly legal (and more readable).
var2 = var1;
var2[0] = 12;
If it ain't broke, I can fix that.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
12-14-2004 08:25 AM
12-14-2004 08:25 AM
Re: Pointer to arrays in g++
Perfect. Now my program is working. Thanks you soo much Clay.
alfonsoarias
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
Company
Events and news
Customer resources
© Copyright 2025 Hewlett Packard Enterprise Development LP