Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

help me with debug errors

Status
Not open for further replies.

john2020

Full Member level 5
Joined
Nov 13, 2005
Messages
292
Helped
12
Reputation
24
Reaction score
8
Trophy points
1,298
Activity points
4,911
I need to know if theres any errors in this code?

#define tPosition struct { int X, int Y } Position *
int myfunc(int x)
{
tPosition a, b;
if (x = 0xF178)
{
unsigned int z = 3;
return a.X * z;
}
return b.X + z;
}
 

replace the #define with typedef and the * after position by ;

In the function replace tPosition with Position.

Also check for the width of the int type to make sure it bigger than 16 bit.
 

do you mean this way?did u notice only error with first line? i think structure definition is wrong here and also variables a and b are used without assigning values here...what about the if loop??have modfied the code as shown below, see now if its ok.

Code:
typedef  struct          {           int X;            int Y;         }Position;int myfunc(int x) { Position a, b;unsigned int z = 3; if (x = 0xF178) { return a.X * z; } return b.X + z; }
 

You are right you need to define the z variable outside of the if. If you don't assign value when declaring a variable, you may see unexpected result.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top