473,320 Members | 2,110 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,320 software developers and data experts.

Pointer questions - GNU c++ on a unix platform

32
I have 3 structures in my header file
struct{
int a;
int b;
} header;

struct{
int c;
int d;
} trailer;

struct{
header hdr;
trailer trl;
} msg_struct;

I declare an instance in my code

msg_struct new_msg;

After I populate new_msg, I then want to pass a pointer to new message to a special printFunc() I have written.

My call to the function
printFunc(&new_msg);

HERE's My first problem -----
What should the function prototype look like in my header file for printFunc()
I have
printFunc(int *)

I get compiler error saying cannot convert int** to int* for argument 1.....

HERE's My second problem -----

In printFunc(), to cout the contents of new_msg, should the line read
std::cout<< new_msg->header.a << std::endl;
std::cout<< new_msg->header.b << std::endl;
etc........

This gives compiler "error expected unqualified-id before '.' token" which I assume means that it doesn't understand what the "new_msg->" is

Any help would be appreciated.

Thanks

emp1953
Dec 3 '07 #1
9 1596
Change your printFunc( int * ) function to printFunc ( msg_struct * new_msg )

that should solve the problems

Max
Dec 3 '07 #2
emp
32
I assume you suggest making the change both in the function declaration in the header file and in the function itself?

When I do that I get a compiler error that says something very similar to original error.

cannot convert msg_struct** to msg_struct*
and the unqualified-id error has not changed
Dec 3 '07 #3
can you post all of the source?
Dec 3 '07 #4
emp
32
What I'm working is sensitive so I'm posting a simplified version
Here's the header file

printFunc.h

struct{
int a;
int b;
} header;

struct{
int c;
ind d;
} trailer;

struct{

header hdr;

trailer trl;

} msg_struct;





void decodeOutput(msg_type_enum, msg_struct *);
void printFunc(msg_struct *);



################################################## ################################





Here's the code.cpp

#include "printFunc.h"

void decodeOutput(msg_type_enum typeIn, msg_struct *msgIn){
{
switch(typeIn)

{

case 0: printFunc(&msgIn);

default: break;

}

}
void printFunc(msg_struct *msgIn)

{

std::cout<< msgin->hdr.a << std::endl;

std::cout<< msgin->hdr.b << std::endl;

std::cout<< msgin->trl.c << std::endl;

std::cout<< msgin->trl.d << std::endl;

}

################################################## #################################


Compiler errors


error: cannot convert int** to int* for argument 1 (""this refers to the case 0 call to printFunc in the switch")

error: expected unqualified-id before '.' token (""This refers to the couts, referring to the msgIn->")
Dec 3 '07 #5
emp
32
Sorry, a correction to my most recent code pose

error: cannot convert msg_struct** to msg_struct* for argument 1 (""this refers to the case 0 call to printFunc in the switch")

error: expected unqualified-id before '.' token (""This refers to the couts, referring to the msgIn->")
Dec 3 '07 #6
It is because you already passed the msg_struct as a pointer to the decode function therefore you do not need to & operator when passing the msg_struct to the printFunc. It should look like this:

case 0:
printFunc( msgln );


Max
Dec 3 '07 #7
emp
32
It is because you already passed the msg_struct as a pointer to the decode function therefore you do not need to & operator when passing the msg_struct to the printFunc. It should look like this:

case 0:
printFunc( msgln );


Max
################################################## ##

Thank You Max, that got rid of the can't convert msg_struct** to msg_struct* error

I still have the compiler error
expected unqualified-id before '.' token

Which I assume is the msgIn-> in my cout....


emp1953
Dec 3 '07 #8
you typed msgin -> ... when it should be msgln

capital vs lowercase

Max
Dec 3 '07 #9
emp
32
you typed msgin -> ... when it should be msgln

capital vs lowercase

Max


Duh! My brain is on caffeine overdose. I hope I don't have to bother you guys with this any more

Thanks again
Dec 3 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: jrefactors | last post by:
when people say unix programmer, does it mean they write programs in unix environment,and those programs are run in unix platform? it is not necessary they are using unix function calls? I heard...
8
by: Mike | last post by:
Hello, I have a few rather urgent questions that I hope someone can help with (I need to figure this out prior to a meeting tomorrow.) First, a bit of background: The company I work for is...
162
by: techievasant | last post by:
hello everyone, Iam vasant from India.. I have a test+interview on C /C++ in the coming month so plz help me by giving some resources of FAQS, interview questions, tracky questions, multiple...
79
by: syntax | last post by:
what is the size of a pointer? suppose i am writing, datatype *ptr; sizeof(ptr); now what does this sizeof(ptr) will give? will it give the size of the
20
by: j0mbolar | last post by:
I was reading page 720 of unix network programming, volume one, second edition. In this udp_write function he does the following: void udp_write(char *buf, <everything else omitted) struct...
2
by: JIM.H. | last post by:
Hello, I have to questions about ASP.NET, I heard that APS.NET is platform independent and it can run in any browser. Here are my questions: 1. Doesn’t ASP.Net require .NET framework, if yes...
17
by: Christian Wittrock | last post by:
Hi, What does ANSI C say about casting an 8 bit pointer to a 16 bit one, when the byte pointer is pointing to an odd address? I have detected a problem in the Samsung CalmShine 16 compiler. This...
30
by: GeorgeRXZ | last post by:
Hi Friends, I have some questions related to C Language. 1What is the difference between the standard C language and Non standard C language ? 2which is better C Lanugage, C under Linux/...
18
by: aj | last post by:
I have the following snippet of code. On some platforms, the delete calls works, on Linux, it core dumps (memory dump) at the delete call. Am I responsible for deleting the memory that...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.