LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-09-2005, 01:37 AM   #1
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Rep: Reputation: 30
scope of an object and global scope


I've got a var. defined as
int fd; globally available throughout my application
in a global include file say #include "myapp.h"

I've got another class which resides on another file
lets say #include "serialport.h"
this class has

serialport:pen()
{
fd = open (....);
}

Return to the globol scope
I've got a non-class reference to fd available which always appears to be 0. Does the scope present an issue?
Thanks
Jack
 
Old 12-09-2005, 07:46 AM   #2
dmail
Member
 
Registered: Oct 2005
Posts: 970

Rep: Reputation: Disabled
so the variable is not defined as static then?
try including the following in "serialport.h" and see if that makes a difference.
Code:
extern int fd;
 
Old 12-09-2005, 08:13 PM   #3
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Still zero. I actually opened the fileHandle with
#include "myapp.h"
extern int fd;
void CSerialPort::Open ()
{
fd = open(...)
}
//////////////////////////////////////////////
and access it this way
extern int fd
#include "myapp.h"
void PortMonitorThread(void)
{
read (fd..)
}

where fd is declared above all cpp files
so
in myapp.h
static int fd;

Thanks
Jack
 
Old 12-09-2005, 08:14 PM   #4
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Typing mistakes. But they compiled okay
 
Old 12-09-2005, 08:39 PM   #5
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
The Callback function was invoked by a thread. Does it pose any problems?
Jack
 
Old 12-09-2005, 08:40 PM   #6
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
PortMonitorThread exactly
 
Old 12-09-2005, 08:50 PM   #7
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
Still zero. I actually opened the fileHandle with
#include "myapp.h"
extern int fd;
void CSerialPort::Open ()
{
fd = open(...)
}
//////////////////////////////////////////////
and access it this way
extern int fd
#include "myapp.h"
void PortMonitorThread(void)
{
read (fd..)
}

where fd is declared above all cpp files
so
in myapp.h
static int fd;

Thanks
Jack
 
Old 12-09-2005, 09:09 PM   #8
lucky6969b
Member
 
Registered: Nov 2005
Posts: 337

Original Poster
Rep: Reputation: 30
It's got to be some C versus C++ scope problems. But I don't know where to look and start. Any hints?
Thanks
Jack
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Python inheritance and scope dakensta Programming 2 07-31-2005 06:16 AM
KDE- Out of Resolution Scope vijayind Fedora 2 02-23-2005 06:59 AM
scope suchi_s Programming 1 10-30-2004 07:07 AM
spamassassin + procmailrc global scope mgbowman Fedora 0 08-17-2004 07:05 PM
question about scope in c++ PTBmilo Programming 7 02-10-2003 04:59 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:22 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration