473,387 Members | 1,597 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,387 software developers and data experts.

structures declaration and definition

is possible to combine structures declaration and definition in programming language

structures declaration and definition
Dec 17 '13 #1
3 1553
weaknessforcats
9,208 Expert Mod 8TB
Exactly what do you mean? Can to give me an example?
Dec 17 '13 #2
donbock
2,426 Expert 2GB
I'm not sure what your question means. If your question is...
Can a structure declaration and a structure definition (for the same structure) both be in the same source file?

The answer to that question is yes. In fact, the best way to connect instances of a structure together into a linked list is to precede the structure definition with a structure declaration:
Expand|Select|Wrap|Line Numbers
  1. struct s;           // structure declaration.
  2. struct s {          // structure definition.
  3.    struct s *next;  // declaration makes this legal.
  4.    ...
  5. };
Dec 17 '13 #3
donbock
2,426 Expert 2GB
On the other hand, if your question is...
Is there any way to combine a structure declaration and structure definition into one thing so I don't have to type both?

The answer to that question is yes. A structure definition counts as a structure declaration. You can get by using only structure definitions.

If that's true then why would you ever bother with a structure declaration? A structure declaration can be used when you want the compiler to know there is a structure, but you don't care if it knows what is in the structure or how big it is. That may not sound useful, but it works just fine if all you want is a pointer to the structure.

A structure declaration is sometimes called an opaque type declaration -- because you can't see what is inside it. A common idiom is to use an opaque type in a library API. One library function allocates a new variable, returning a pointer to it (sometimes called a handle). This pointer is then passed to the other functions in the library. The structure is defined within the library, but it is only declared in the library API. An example of this technique is the FILE* argument used in stdio.h.
Dec 17 '13 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: John Ratliff | last post by:
I'm having issues with forward declarations and possibly member variables. Can you declare a member variable and pass it parameters. class x { private: y obj(this); } Is that valid? I'm...
3
by: Henning Hasemann | last post by:
Hi all, On larger projects I used the following 'technique' (well in fact its a really simple thing): 1. Write one source-code file for each 'large' class and one corresponding header file....
7
by: Kristian Virkus | last post by:
Hello! I would like to write a C programm with multiple include files, where one may use another one (to print the value of a variable). When I try to compile the program below, the linker...
1
by: wtu | last post by:
function Declaration&Definition -------------------------------------------------------------------------------- " Geroty (const vector<Point3D>& poly, const Plane& Tr)" As i'm c++ beginner...
2
by: Laurent Deniau | last post by:
I would like to know why the following small program does not compile (checked with gcc 4.1.2) and if the compiler behavior is correct: struct A; typedef void (T)(struct A*); void f(void) {...
4
by: =?utf-8?b?QXNiasO4cm4gU8OmYsO4?= | last post by:
Suppose I have a function that takes a pointer as its input, but does not change what the pointer points to. In that case, the const qualifier can be used to indicate that the variable pointed to...
5
by: ruebezaehler | last post by:
Hello, I should separate the definition and declaration of template code. This works fine for non-specialized templates. But I do not know how to do this for specialized templates. Example: ...
6
by: Annonymous Coward | last post by:
I am relatively new in C#, but have several years C++/Java. I am writing a little C# console app to "test the waters" and learn the language. If I have a class defined as: class MyClass {...
10
by: Jeffrey | last post by:
My understanding is that if you write class X { int y; static int z; }; then you've defined (and declared) X and y, but you have only declared (and not defined) z. If you'd like to...
1
by: michaelhsilva | last post by:
Hi folks! Is there anybody that can tell me what´s wrong with this template. I´ve migrate from VC++ 6 to VS 2010. template<int _Idx, class _Ty1, class _Ty2> typename _Pair_data<_Idx, _STD...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.