Thread: Visibility

  1. #1
    Registered User
    Join Date
    Feb 2022
    Location
    Canada, PEI
    Posts
    103

    Visibility

    I'm wondering how visibility is granted to one file while being restricted in another.

    Say I have a function 'void second_hello()' which is defined in the second.c file and I want that to be available in the first.c file but not in the main.c file.. Basically I want to call a function in first.c which calls the function in second.c because I want the function in second.c hidden from main.c. Hope that makes sense.

    Here's what I tried.

    second.h
    Code:
    #ifndef SECOND__HH
    #define SECOND__HH
    
    void second_hello();
    
    #endif
    second.c
    Code:
    #include <stdio.h>
    #include "second.h"
    
    void second_hello() {//this should only be available in first.c
      fputs("Hello world from the second!\n", stdout);
    }
    first.h
    Code:
    #ifndef FIRST__HH
    #define FIRST__HH
    
    void first_hello();
    
    #endif
    first.c
    Code:
    #include "first.h"
    #include "second.h"
    
    void first_hello() {
      second_hello();
    }
    main.c
    Code:
    #include <stdio.h>
    #include "first.h"
    
    int main(int argc, char ** argv) {
      first_hello();//which calls second_hello()
      return 0;
    }
    Is the above code a proper way to restrict visibility of 'void second_hello()'?

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Looks good to me.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. XNa C# visibility priority
    By Shingetsu Kurai in forum Game Programming
    Replies: 2
    Last Post: 01-07-2012, 06:55 AM
  2. #define visibility
    By mynickmynick in forum C Programming
    Replies: 3
    Last Post: 04-19-2011, 03:12 AM
  3. Check application visibility
    By 3saul in forum Linux Programming
    Replies: 2
    Last Post: 02-13-2006, 05:13 PM
  4. Process visibility
    By SMurf in forum Windows Programming
    Replies: 5
    Last Post: 11-17-2003, 09:00 PM
  5. scoping visibility
    By dirgni in forum C++ Programming
    Replies: 2
    Last Post: 12-02-2002, 04:16 PM

Tags for this Thread