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

typedef of array compiling problems in functions call

Hi all,
I have a problem with the next example code. I can't compile it without
warnings with gcc.
The compilation out is:
$ gcc -Wall aPoint.c
aPoint.c: In function 'printaPoint2':
aPoint.c:23: warning: passing argument 1 of 'printaPoint1' from incompatible
pointer type
aPoint.c: In function 'printaPoint3':
aPoint.c:30: warning: passing argument 1 of 'printaPoint1' from incompatible
pointer type

and the call to printaPoint1 in printaPoint3 don't work, it shows strange
results
can someone help me to solve this doubt??

Thanks all

/**********************************aPoint.c******** *****************************/
/*gcc -Wall aPoint.c */
#include <stdio.h>
#include <stdlib.h>

typedef float aPoint[3];
//typedef struct {float a[3];}aPoint;

void printaPoint1(aPoint *pto)
{
int i;
//printf("printaPoint1: ptr=0x%X\n",&pto);
for(i=0;i<3;i++)
printf("%f ",(*pto)[i]);
printf("\n");
//for(i=0;i<3;i++) printf("%f ",(pto)[i]);printf("\n");

}

void printaPoint2(aPoint pto)
{
//printf("printaPoint2: ptr=0x%X &ptr=0x%X \n",pto,&pto);
printaPoint1(pto);

}

void printaPoint3(aPoint pto)
{
//printf("printaPoint2: ptr=0x%X &ptr=0x%X \n",pto,&pto);
printaPoint1(&pto);

}
int main()
{
aPoint pto;
pto[0]=1;
pto[1]=2;
pto[2]=3;
printf("call printaPoint1\n");
printaPoint1(&pto);
printf("call printaPoint2\n");
printaPoint2(pto);
printf("call printaPoint3\n");
printaPoint3(pto);
return 0;
}
~

Jul 1 '07 #1
2 1469
Rufus wrote, On 01/07/07 21:24:
Hi all,
I have a problem with the next example code. I can't compile it without
warnings with gcc.
The compilation out is:
$ gcc -Wall aPoint.c
You should add a few more options.
gxx -ansi -pedantic -Wall -O aPoint.c
Adding either -W or -Wextra depending on your version would be useful as
well.
aPoint.c: In function 'printaPoint2':
aPoint.c:23: warning: passing argument 1 of 'printaPoint1' from incompatible
pointer type
aPoint.c: In function 'printaPoint3':
aPoint.c:30: warning: passing argument 1 of 'printaPoint1' from incompatible
pointer type

and the call to printaPoint1 in printaPoint3 don't work, it shows strange
results
Well, it would, seeing is your code is fundamentally broken.
can someone help me to solve this doubt??

Thanks all

/**********************************aPoint.c******** *****************************/
/*gcc -Wall aPoint.c */
#include <stdio.h>
#include <stdlib.h>

typedef float aPoint[3];
//typedef struct {float a[3];}aPoint;

void printaPoint1(aPoint *pto)
{
Here define printaPoint1 as taking a pointer to aPoint.

<snip>
void printaPoint2(aPoint pto)
{
//printf("printaPoint2: ptr=0x%X &ptr=0x%X \n",pto,&pto);
printaPoint1(pto);
Here you pass an aPoint rather than a pointer to one. This is WRONG.
}

void printaPoint3(aPoint pto)
{
//printf("printaPoint2: ptr=0x%X &ptr=0x%X \n",pto,&pto);
printaPoint1(&pto);
<snip>

Here you are getting tripped up by your typedef and the fact that when
you attempt to specify a parameter as being an array, it is really just
a pointer.

Your code is such a mess I don't know what you are actually trying to
do, but whatever it is you are not trying to do it the right way. If you
tell us what you want to do as well as giving us your code people are
more likely to be able to point you in the right direction. However, I
suggest you start by reading section 6 of the comp.lang.c FAQ available
at http://c-faq.com/
--
Flash Gordon
Jul 1 '07 #2
On Jul 2, 8:24 am, Rufus <n...@yahoo.eswrote:
I have a problem with the next example code. I can't compile it without
warnings with gcc.

typedef float aPoint[3];
Many people prefer to not use array typedefs;
your code is a good example of the confusion
that can arise when they are used.

Jul 1 '07 #3

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

Similar topics

7
by: Tony Johansson | last post by:
Hello Experts! I have the following Array template class see below. I execute these three statements statement 1: Array<int> x(5); statement 2: cin >>x; statement 3: Array<int>::element_type ...
14
by: dreamcatcher | last post by:
I always have this idea that typedef a data type especially a structure is very convenient in coding, but my teacher insisted that I should use the full struct declaration and no further...
5
by: Cancerbero | last post by:
Hi (first, excuse me for my bad english) As I know, the semantics for typedef is: typedef A B; I think this makes B a synonym of A, where A is an existing data type. Is that right? Based...
5
by: Russell Shaw | last post by:
Hi, In setjmp.h on a linux system, there is: typedef struct __jmp_buf_tag { ... } jmp_buf; I could understand typedef struct { } jmp_buf, but how do i interpret typedef struct { } jmp_buf ?
16
by: burn | last post by:
Hello, i am writing a program under linux in c and compile my code with make and gcc. Now i have 4 files: init.c/h and packets.c/h. Each header-file contains some: init.h: struct xyz {
2
by: Patrick Kowalzick | last post by:
Hello NG, sorry to bother again, but I am a lit surprised that I got no answer on my post (attached below). So I refined the code a little bit :-). If there is a typedefed class X inside a...
14
by: yang__lee | last post by:
Hi, You all know typedef typedef struct g { int a; int b; } google;
0
by: phoolimin | last post by:
Dear all, I am trying to embed python into another scripting language, to do this I need to solve a number of problems on importing or compiling python script. First let me state what exactly I...
5
by: Immortal Nephi | last post by:
I would like to design an object using class. How can this class contain 10 member functions. Put 10 member functions into member function pointer array. One member function uses switch to call...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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
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,...
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.