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 5036 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.
Parents
  • shabaz
    0 shabaz over 2 years ago

    Hi Cris,

    The C++ guru comments equally apply to C. According to this website, the Motor Industry Software Reliability manual also states exactly what is being suggested, and this applies specifically to C programming: 

    image

    If you define a variable (which is an object) without static and outside of a function, in a header file, then to adhere to that rule, you'd also need an extern declaration in a header file too, i.e. you'd need to #include another header file in the header file! Currently your code does not do that either, but it wouldn't be a good way anyway.

    In contrast, the more normal approach which meets that rule, is to define in a C file and then to #include a file containing extern where needed.

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

     shabazjust a side note. I meet him years ago while I was in NJ. at his about  C with Classes, sort of a preprocessor at Princeton, We all thought it was a joke. If you want to write with classes use Java as that is what it was designed to do. While  Don Knuth did in fact win the ACM Turning Award (74) and his series "The Art of Computer Programming" ( must-reads! alas, BS did not, nor did the ass from Apple. In my humble opinion, Brian W. Kernighan and Dennis M. Ritchie(83)  {AMC Turring Award} did more by developing  C and Unix than anybody in the history of computing. While working at Inderdata I installed 8/32 #1 at Bell labs where I meet them both. 

    also, I noted that in one example of typedef a struct  stack exchange: 

    typedef struct {
      unsigned char current;
      unsigned char start;
      unsigned char target;
      unsigned long startTime;
      unsigned int duration;
    } led;
    This i beleave is an ilegale contruction as 'struct' is a key or reserved word

    I just hung it on my server: http://nexgen-simulations.com/E14/NexGen:%20Hacking/landingGear/

    ~~ 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
    phoenixcomm said:
    This i beleave is an ilegale contruction as 'struct' is a key or reserved word

    It is a legal construct. You assign a type to that particular struct definition.

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

    C++ pre-dates Java.

    "C++ ..... created by Danish computer scientist Bjarne Stroustrup. First released in 1985 as an extension of the C programming language"

    "Java was originally developed by James Gosling at Sun Microsystems. It was released in May 1995 as a "

    Both quotes form Wikipedia:

    en.wikipedia.org/.../Java_(programming_language)

    https://en.wikipedia.org/wiki/C++

    SO if you wanted to write with classes in the  before 1995 then Java wasn't an option.

    There were other options:

    https://en.wikipedia.org/wiki/Object-oriented_programming

    but C++ was a brave (and in many ways successful) attempt to bring Oop and C together.

    C itself was not entirely original work:

    BCPL -> B -> C

    Wikipedia has good articles on the history of all of them.

    MK

    • 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

    What's a "q type" Jan?

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

    Smalltalk ruled!!

    • 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 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
Reply
  • 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
Children
No Data
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