Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7656379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T12:44:58+00:00 2026-05-31T12:44:58+00:00

This is a question is w.r.t to my assignment in my Operating Systems Class.

  • 0

This is a question is w.r.t to my assignment in my Operating Systems Class. I am not posting the code, but asking a general doubt. Since the project is to build an OS, there are no debugging tools. So any help is appreciated.

I have a header file which looks like this:

class test { 

private:
    unsigned long base_address;
    unsigned long size;  

public:
    test();
    void method1();
    void method2();

};

The corresponding C file looks like this:

#include "test.H"

unsigned long table;    

test::test(){
    base_address = some_value; //initialise the variables
    size = some_other_value;
    table = another_value;
    //some code
}

void test::method1(){
    //some code
}

void test::method2(){
    //some code
}

This code works fine, and I get the desired output. My problem is that I wanted to make the variable “table” (currently declared and used throughout all the functions in the C file), as a class variable. When I remove it from the C file and put it under the private variables in the header file, it compiles fine but then my output blows up.
Any pointers to what I should look into.? (Sorry I know its hard without knowing the context, but thanks for the help.)

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T12:44:59+00:00Added an answer on May 31, 2026 at 12:44 pm

    Is “another_value” supposed to represent a magic number or another vaiable? First things first, you should assign all primitives an initial value when they are defined. Don’t use magic numbers, used #define ANOTHER_VALUE 0, if this is the case.

    When I remove it from the C file and put it under the private variables in the header file, it compiles fine but then my output blows up.

    Probably because you need to extern “C” they variable, if you are pulling in the protoype for use from c code:

    How do I use extern to share variables between source files?

    Here’s a compiling example:

    externTest.hpp

    /*
     * externTest.hpp
     *
     *  Created on: Mar 15, 2012
     */
    
    #ifndef EXTERNTEST_HPP_
    #define EXTERNTEST_HPP_
    
    class eTest
    {
    private:
        unsigned long m_test;
    
    public:
        eTest();
    
        void testValue();
    };
    
    
    #endif /* EXTERNTEST_HPP_ */
    

    externTest.cpp

    //============================================================================
    // Name        : externTest.cpp
    // Author      : 
    // Version     :
    //============================================================================
    #include <stdio.h>
    #include <stdlib.h>
    #include <iostream>
    #include "externTest.hpp"
    
    extern "C" {
    #include "value.h"
    }
    
    using namespace std;
    
    eTest::eTest() {
        m_test=global_table;
    }
    
    void eTest::testValue() {
        printf("Global C Value: %lu \n", global_table);
        cout << "Test global value: " << m_test << endl;
    }
    

    value.h

    /*
     * value.h
     *
     *  Created on: Mar 15, 2012
     */
    
    #ifndef VALUE_H_
    #define VALUE_H_
    
    extern unsigned long global_table;
    
    void assign_value(unsigned long lValue);
    
    void print_global_value();
    
    #endif /* VALUE_H_ */
    

    value.c

    /*
     * value.c
     *
     *  Created on: Mar 15, 2012
     */
    
    #include "value.h"
    
    unsigned long global_table;
    
    void assign_value(unsigned long lValue) {
        global_table=lValue;
    }
    
    void print_global_value() {
        printf("Global C Value: %lu \n", global_table);
    }
    

    If you want to use the physical address of table, just make m_test a pointer to global_table:

    private:
        unsigned long *m_test;
    

    Be sure to dereference your pointer for the value:

    eTest::eTest() {
        m_test=&global_table;
    }
    
    void eTest::testValue() {
        printf("Global C Value: %lu \n", global_table);
        cout << "Test global value: " << *m_test << endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Disclaimer: This is for a homework assignment, but the question is not regarding the
This is my assignment question Create a class with its own operator new. This
This is a question corresponds to my uni assignment so I am very sorry
This is part of a homework assignment. I've got several questions asking find the
This isn't a school assignment or anything, but I realize it's a mostly academic
I am working on an assignment for my Operating System class (Posix & C),
Disclaimer: this question is directly related to my programming homework. My C++ assignment consists
This question is not about any error I'm currently seeing, it's more about theory
Intrigued by this question , I have played a bit with parallel assignment with
Inspired by this question . Usually the reason to make copy-constructor and assignment operator

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.