Thread: Modular Programming

  1. #1
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127

    Modular Programming

    hi all
    take a look at this codes
    Code:
    /*source.c*/
    #include<stdio.h>
    #include "file.h"
    main()
    {
          char *name="strom man\n";
          sy_hay(name);
          }
    Code:
    /*file.c*/
    #include "file.h"
    void say_hay(char *string)
    {
         printf("Hy %s",string);
         }
    Code:
    /*file.h*/
    void say_hay(char *string);
    i get this
    Code:
      Circular ss <- ss.o dependency dropped.
    ? i don't get it ? why is that?

  2. #2
    Fear the Reaper...
    Join Date
    Aug 2005
    Location
    Toronto, Ontario, Canada
    Posts
    625
    Why are you including file.h in file.c ?
    Teacher: "You connect with Internet Explorer, but what is your browser? You know, Yahoo, Webcrawler...?" It's great to see the educational system moving in the right direction

  3. #3
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    It gives me a linker error
    Code:
    /*source.c*/
    #include<stdio.h>
    #include "file.h"
    main()
    {
          char *name="strom man\n";
          sy_hay(name);  // shouldn't it be say_hay(name);
    }
    but hen what is ss and ss.o ?

    BTW including file.h in file.c is ok but not necessary in this case.

    Kurt

  4. #4
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    file.h has already been included by "source.c", but it's been included again by "file.c"

    You need some 'inclusion guards'

    ie in file.h

    Code:
    #ifndef INCLUDED_FILE_H
    #define INCLUDED_FILE_H
    
    extern void say_hay(char * string);
    
    #endif /* INCLUDED_FILE_H */

  5. #5
    Registered User
    Join Date
    Aug 2005
    Location
    Austria
    Posts
    1,990
    Quote Originally Posted by zacs7 View Post
    You need some 'inclusion guards'
    They are always a good idea but not "needed" in this case.

    We have two compilation units in this case. each includes file.h only once -> no problem.
    'inclusion guards' protect against multiple inclusions in the same compilation unit only.
    Kurt

  6. #6
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    Sorry, it's become a habit for me to use them everywhere

    Just incase it is included more than once

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Willie Mays won't like it unless "say_hay" is spelled the same in all three files.

    Edit:

    I was suggesting that the spelling might be the cause of errors in your program, of course.
    Last edited by Adak; 05-10-2007 at 06:10 AM.

  8. #8
    life is a nightmare
    Join Date
    Apr 2007
    Posts
    127
    sorry about the spelling
    and thanks for the advices
    i will be back

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Modular
    By loopshot in forum Game Programming
    Replies: 7
    Last Post: 01-20-2006, 07:24 PM
  2. Modular math
    By PJYelton in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 10-01-2003, 08:35 AM
  3. Modular programming
    By Longie in forum Linux Programming
    Replies: 1
    Last Post: 07-08-2003, 11:03 PM
  4. Modular Division problem
    By Malek in forum C++ Programming
    Replies: 7
    Last Post: 05-24-2003, 06:08 PM
  5. Completely modular motherboards?
    By SMurf in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 02-23-2003, 12:56 PM