473,385 Members | 1,901 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

extern question

I am trying to create a message box that allows you to enter a name
then display that name on a window. The program uses win32 but that is
not the issue. I want have a global buf variable. So that it can be
filled in the window then displayed in the main window.

Here is what I have

char * buf = NULL; //In my min program.

extern char * buf; // This is the section where I want buf displayed.

extern char * buf; //This is where I fill the array.
buf = new char[len];
GetDlgItemText(hwnd, IDC_NAME_EDIT, buf, len +1);
I have used extern before and it had made my progam possible but does
it work with a pointer?

Jun 6 '06 #1
2 2011

"JoeC" <en*****@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
I am trying to create a message box that allows you to enter a name
then display that name on a window. The program uses win32 but that is
not the issue. I want have a global buf variable. So that it can be
filled in the window then displayed in the main window.

Here is what I have

char * buf = NULL; //In my min program.

extern char * buf; // This is the section where I want buf displayed.

extern char * buf; //This is where I fill the array.
buf = new char[len];
GetDlgItemText(hwnd, IDC_NAME_EDIT, buf, len +1);
I have used extern before and it had made my progam possible but does
it work with a pointer?

Yes, a pointer is just like any other variable. You can have a global
pointer and set the value of the pointer to whatever you want in another
module. That module has to have a extern declaration for the pointer. As a
general rule I have one extern declaration in one header and one definition
in one c/c++ file.

Not all globals are bad but whether you should use a global in this
particular case is a different question.

Andrew
Jun 6 '06 #2

andrew queisser wrote:
"JoeC" <en*****@yahoo.com> wrote in message
news:11**********************@y43g2000cwc.googlegr oups.com...
I am trying to create a message box that allows you to enter a name
then display that name on a window. The program uses win32 but that is
not the issue. I want have a global buf variable. So that it can be
filled in the window then displayed in the main window.

Here is what I have

char * buf = NULL; //In my min program.

extern char * buf; // This is the section where I want buf displayed.

extern char * buf; //This is where I fill the array.
buf = new char[len];
GetDlgItemText(hwnd, IDC_NAME_EDIT, buf, len +1);
I have used extern before and it had made my progam possible but does
it work with a pointer?

Yes, a pointer is just like any other variable. You can have a global
pointer and set the value of the pointer to whatever you want in another
module. That module has to have a extern declaration for the pointer. As a
general rule I have one extern declaration in one header and one definition
in one c/c++ file.

Not all globals are bad but whether you should use a global in this
particular case is a different question.

Andrew


At first it didn't work and now it does.

Jun 6 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: John Ratliff | last post by:
I have a few global variables in my app. They are defined in the main application class file and declared (extern) in a header which can be included by anyone who would want to use these variables....
10
by: Mark A. Gibbs | last post by:
I have a question about mixing C and C++. In a C++ translation unit, I want to define a function with internal linkage and C calling convention. Here's a sample of what I want to do: //...
12
by: G Patel | last post by:
I've seen some code with extern modifiers in front of variables declared inside blocks. Are these purely definitions (no definition) or are they definitions with static duration but external...
29
by: DevarajA | last post by:
Can anyone explain me what extern is used for? I thought it was used to declare variables definited in other files, but i can do that also without extern. /*file a.c*/ int a=5; int main() {...
5
by: siliconwafer | last post by:
Hi all, I wanted to know that is use of extern keyword mandatory in case of global variables and functions used in other source files? i.e consider a following piece of code from MSDN explaining...
7
by: MikeF | last post by:
Group, I have a variable declared in 'main.c' as: const unsigned int x = 1; I have another module which uses this same variable, I've tried to declare as:
5
by: Christian Christmann | last post by:
Hi, I've tree questions on the storage class specifier "extern": 1) Code example: int main( void ) { int b = -2; // my line 3 if ( a ) {
7
by: Christian Christmann | last post by:
Hi, I've a a question on the specifier extern. Code example: void func( void ) { extern int e; //...
7
by: blangela | last post by:
I am currently taking a course and one of the example programs showed a function prototype something like: extern void func(); I asked why the "extern" was necessary. Someone in the class...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.