BPsite Forums
November 24, 2024, 03:06:43 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: BPSITE FOREVER!
 
   Home   Help Search Members Login Register  
Pages: [1]
  Print  
Author Topic: UNIX  (Read 6941 times)
smi256
Hero Member
*****
Offline Offline

Posts: 2287



View Profile
« on: February 02, 2007, 08:04:26 AM »

I, for the of me, can't write my own Makefile.
What it is that I want to do is have three files:
main.c - which will #include "functions.h"
functions.c - which will have functions in it, lets call them: foo() and bar()
functions.h - which has the declaration of foo()

The thing is that I want main.c to be able to call foo(), but not bar().

***** main.c *****
#include <stdio.h>
#include <stdlib.h>
#include "functions.h"

main()
{  
   foo();
}//end main


***** functions.h *****
void foo(void);


***** functions.c *****
#include <stdio.h>
#include <stdlib.h>
#include "functions.h"

void foo(void)
{  
   bar();
}//end foo

void bar(void)
{  
   printf("\nMeow?\n\n");
}//end bar



This is what I have for a make file:
***** Makefile *****
TEST2.exe : main.o functions.o
   cc main.o functions.o -o TEST2.exe

main.o : main.c
   cc -c main.c

functions.o : functions.c functions.h
   cc -c functions.c


The problem that I have is that with this setup, I can still call bar() from my main.c file...  Sad   I don't even know if I'm making my Makefile correctly.  :unsure:
What do I do? :cry:
« Last Edit: February 02, 2007, 08:05:03 AM by smi256 » Logged

*was here
Rug
Moderator
Hero Member
*****
Offline Offline

Posts: 9126


View Profile
« Reply #1 on: February 02, 2007, 01:00:55 PM »

The problem is that you're using Unix, you snob. Linux is good enough for most people who like money Tongue.
Logged
Hornet
Hero Member
*****
Offline Offline

Posts: 685



View Profile WWW
« Reply #2 on: February 02, 2007, 06:56:18 PM »

Not a clue about C, sorry to say.

In PHP, which is quite similar, one way around it would be to have bar() inside another function, and call that within the file that you want to be able to access bar().

Why on earth would you not want it to be able to reach a particular function, though?  If you don't want it, don't call it, and if you want something with the same name, just change it's name and use that instead.

Code:
function One () {
     print 'One<br />';
}

function Two () {
     function TwoA () {
          print 'TwoA<br />';
     }
}

One();
Two(); //don't call Two() if you want to hide TwoA
TwoA(); //Depending on how C handles things, you might want to wrap this in an 'if function exists' type clause.
« Last Edit: February 02, 2007, 06:57:19 PM by Hornet » Logged

In the fridge! By the cheese! Waggle waggle!

Money isn't the solution to life's problems, but it can usually buy it.
SS
Administrator
Hero Member
*****
Offline Offline

Posts: 10393



View Profile WWW
« Reply #3 on: February 02, 2007, 09:49:17 PM »

My C is rusty, but don't you just do:


public void alice()
{
 bob();
}

private void bob()
{
 printf("Woof!");
}



Or something along those lines anyway.
Logged

Peter 'SpectralShadows' Boughton,
Seeker of Perfection, BPsite Sitelord.

Till shade is gone, till water is gone, into the Shadow with teeth bared, screaming
defiance with the last breath, to spit in the Sightblinder's eye on the Last Day.
smi256
Hero Member
*****
Offline Offline

Posts: 2287



View Profile
« Reply #4 on: February 03, 2007, 02:46:08 AM »

Quote
The problem is that you're using Unix, you snob. Linux is good enough for most people who like money Tongue.
I agree, But we are forced to use UNIX at UCSC.

Hornet and SS,
I know those two methods work in Java, but I don't think they are in line with ANCII C

We're using cc on the UNIX systems to compile our programs :-( which means I can't sneak in any C++ is I wanted any OOP functionality.
I'll try anyway in spite of my thoughts.  I'm also going to try using static to hide my private functions.
« Last Edit: February 03, 2007, 02:46:32 AM by smi256 » Logged

*was here
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.16 | SMF © 2011, Simple Machines Valid XHTML 1.0! Valid CSS!