element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • About Us
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Hi, I need some hellp with my code structure.
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 38 replies
  • Subscribers 384 subscribers
  • Views 5066 views
  • Users 0 members are here
Related

Hi, I need some hellp with my code structure.

phoenixcomm
phoenixcomm over 2 years ago

for you that don't know I grew up writing C code. So my Code Base has multiple files currently working on my Landing Gear for my sim. 

I have the following files in the LandingGear directory:
LandingGear.ino
isr1.c through isr5.c 
lamps.c 
and landingGear.h

so in lamps.c  i have my code for the lamp test. 

void lampTest( int state ){
for( int count = 0; count < 10; count++;) {
digitalWrite( Lamps.pin[count] ); }
}

it is called from isr4 (isr4.c)

it is also  declared in landingGear.h


#define TRUE 1
#define FALSE -1
#define ON 1
#define OFF 0

/************************** Prototypes *****************************/

void lampTest( int state );
void lamp( Lamps.pin[count], int state );
void blink( Lamps.pin[count] );

typedef struct Lamps{
char name[];
char name[];
lamp} Lamps[] = {
{22, "RIGHT", "RED"}, {23, "NOSE", "RED"}, {24, "LEFT", "RED"},
{25, "RIGHT", "GREEN"}, {26, "NOSE", "GREEN"}, {27, "LEFT", "GREEN"},
{28, "WARNnose", "GREEN"}, {29, "WARNgear, "ORANGE"}, {30, "WARNnoseDis, "BLUE"}, {31, "WARNskid", "RED"}};

and pucks with this isr4.c:2:12: error: ‘ON’ undeclared (first use in this function)    lampTest( ON );

cam anybody give me a straight answer why this happens???

~~  thanks C Harrison

  • Sign in to reply
  • Cancel

Top Replies

  • shabaz
    shabaz over 2 years ago +8
    Hi Cris, The following rules extremely strong guidelines I think apply to your specific scenarios: (1) For every .c file apart from main.c, create a header file with the same name. Otherwise, it's…
  • shabaz
    shabaz over 2 years ago in reply to phoenixcomm +5
    Hi Cris, This is what's causing the problems, because there will be corner-cases (sometimes more often than not) where things will break down and not compile (as you have seen) unless those guidelines…
  • ntewinkel
    ntewinkel over 2 years ago in reply to shabaz +3
    What shabaz said ^ It can be tempting to cut corners by skipping coding best practices, but then you often run into issues that cost you so much more time and frustration later.
  • Jan Cumps
    0 Jan Cumps over 2 years ago in reply to Andrew J

    That's me typing an A on a QUERTY keyboard without looking...

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Andrew J
    0 Andrew J over 2 years ago in reply to Jan Cumps

    Ah, ok...I thought it was some special C thing.  You know, like right hand values and left hand values (whatever it's actually termed!)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 2 years ago in reply to Andrew J

    Fixed it Grin

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • phoenixcomm
    0 phoenixcomm over 2 years ago in reply to Jan Cumps

    no you can NOT typedef a struct with out the name of the struct is and the name of it typedefed!

    case in point typedef struct { int thing; char abc; char name[10]; } led; this begs the question what is the advantage of this? None;  he is trying to rename the struct but it only has one name listed::= led; which is the same as struct { int thing; char abc; char name[10]; } led;   if on the other hand if had done this: typedef struct led { int thing; char abc; char name[10]; } led; you still end up with what we started with. But lets make some use of the typedef like this: typedef struct led { int thing; char abc; char name[10]; } warninLamp; now the typedef of led is now warningLamp.. 

    Now does it make sense you all?? CAH

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 2 years ago in reply to phoenixcomm

    image

    • Cancel
    • Vote Up +3 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • phoenixcomm
    0 phoenixcomm over 2 years ago in reply to Jan Cumps

     Jan Cumps  Duh, you got it. i hope.

    Do you now understand my comment? why the first example on stack exchange is junk?? and would have made more sense if he never used typedef which is just trash and hyperbole. furthermore, I think Eclipse with GCC would have flagged it.  I just don't like the Arduino IDE! it's very crude, you cant build CLEAN, and its SAVE function does not work as you will lose your .h files. or you can't write over the original code (DUH?). 

    I think the IDE should be ABANDONED! and use the C/C++ Eclipse tool set with Arduino PlugIn.  ~~ CAH there is a word that comes to mind. but you said it upsets people. You will Please note there is a third definition. where it can refer to inanimate objects. 

    • Cancel
    • Vote Up -1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • Jan Cumps
    0 Jan Cumps over 2 years ago in reply to phoenixcomm
    phoenixcomm said:
    I think Eclipse with GCC would have flagged it. 

    Best test is to try it, and see.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • phoenixcomm
    0 phoenixcomm over 2 years ago in reply to Andrew J

     Andrew J nah, don't like it. PERL is better for strings, unfortunatly it is typeless which means if you had 4 oranges and 3 apples you will end up with 7 fruits :)) imageand if you are up for it try APL, great for math and 3D stuff, Fortran has been replace by C. ~~CAH

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
<
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube