|
You only need prototypes for forward declarations. And IDEs do not do the compiling, that's the compiler's job.
|
|
|
|
|
True, but I have been using IDE whose authors are very fond of their "beginners feature " which actually builds prototypes "for you". So they claim.
I am now test driving another IDE, still based on GCC and the first test function I used compiled without prototype, that is why I made this post.
Next function failed without prototype, so I am not sure what is going on.
So what is the difference between prototype and forward declaration?
Or is there a difference?
|
|
|
|
|
When the compiler comes across a function call it checks its tables for a declared prototype. If it cannot find one then it will infer a definition from the parameters of the function call. When it then finds the actual function it will check that the definition matches the stored declaration. If it does, then all well and good. If it does not then it will throw out an error message.
As to your last question, a prototype is a forward declaration. It just tells the compiler the type of the parameters and return value of the function, so it can check on any calls made to the function before it is found in the source. The same applies to external functions whose prototypes are in .h files.
|
|
|
|
|
A declaration (prototype) describes an object (function, class, variable).
int some_function(int some_arg);
A definition (implementation) implements an object.
int some_function(int some_arg)
{
int result = 0;
return result;
}
If there is no declaration for an object, the definition implies the declaration.
The compiler needs a declaration when an object is used the first time (accessing a variable, calling a function). So there is no need for a declaration if the first usage is located after the definition in the source code.
While strictly speaking all declarations are forward declarations, the term is mainly used with function declarations in header files where a pointer or reference to another class is passed as function argument. An example:
class OtherClass;
class MyClass
{
MyClass();
SomeFunction(OtherClass &otherClass);
}; The implementation file of MyClass must still include the header file containing the OtherClass declaration. But the above header file must not do so which reduces the compile time. More important, this must be used when both classes use the other which would normally require that both header files include each other which would lock the compiler (recursive inclusion).
See also this SO thread: c++ - What is the difference between a definition and a declaration? - Stack Overflow[^]
|
|
|
|
|
The compiler needs a declaration when an object is used the first time (accessing a variable, calling a function). So there is no need for a declaration if the first usage is located after the definition in the source code.
Perfect answer - that is exactly why my test function - first one in header file - did not need declaration.
Jochen,
I really appreciate your help - always right to the point. Thanks
PS
Are you by any chance teacher / instructor ? You sure know how to explain stuff.
Cheers
Vaclav
|
|
|
|
|
Thank you.
I'm not a teacher. I'm an R&D engineer (hardware and software).
|
|
|
|
|
A function definition is also a declaration if there was none so far. The compiler (not the IDE) will add it to it's internal declaration list when processing such a function.
|
|
|
|
|
Hi
I have C/C++ solution/project
The parent process is C the child process is MFC C++.
Each in its own project
The C project has a number of threads.
I have a quad core laptop.
Is there any way of knowing how many cores the .exe(s) is/are using. Don't know if task manager is the answer.
More so can I have an affinity of a thread to a core ?
Thanks
|
|
|
|
|
It is all handled by the operation system. Don't care about. While it is possible to set a thread affinity it is usually not necessary and often counterproductive.
If a process has multiple threads it will use multiple cores when available. But there is no single core assigned to a specific thread. The OS assigns the cores so that a thread runs on different cores.
|
|
|
|
|
Is there anything in task manager or VS debugger or maybe the Kernal debugger that would show me any information about this
Thanks
|
|
|
|
|
Showing information about the core that runs a specific thread makes no sense due to the fast switching between the cores.
For process information have a look at the Sysinternals Suite[^].
|
|
|
|
|
Thanks so much 
|
|
|
|
|
I wanted to make a program like this:
A bank in Indonesia want to create a program using the order of priority. The purpose of this program is to provide the serial number to its customers. No sequence given later be called by the program so that customers who have no it can go to the teller who had been appointed.
The problem in the bank there is a priority system that puts people who have a priority, so that when the customer has priority can be called up in advance from customers who do not have a priority. Create a program using DLLC to overcome this!
|
|
|
|
|
|
Sorry, but no one here is going to do your work for you. Give it a try, and if you have a specific technical question then come back and people will try to help you.
|
|
|
|
|
Okay, and?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
Yudha Eka Saputra wrote: Create a program using DLLC to overcome this
No thanks. I would change banks if my bank started treating customers this way.
Speed of sound - 1100 ft/sec
Speed of light - 186,000 mi/sec
Speed of stupid - instantaneous.
|
|
|
|
|
Hi...
I am trying to migrate a large MFC solution from VS2005 to VS2015. The solution contains 170 projects. After a lot of work, all projects compile and 168 of them link. One that does not link is petty, but pesky, and I may return to that in another post. The other that does not link is the project that generates the program executable.
* The error that it generates is LNK1104: Cannot Open 'mfc80d.lib'.
* If I ignore MFC80d.lib, I get LNK1104: Cannot Open 'mfcs80d.lib'.
* If I ignore that, I get LNK1104: Cannot Open 'daouuid.lib'
* And if I ignore that, I get any number of undefined externals such as CRect::...(), CSize::...(), CFile::...() and so on. This is presumably because I am not linking MFC at all.
I have found a lot of discussion about this but none of it seems to help me. I can find no explicit or implicit references to MFC 8 in my properties or any project file. I have searched for 'mfc80d' both internally in VS2015 and externally in the Windows 7 search tool.
My target platform is 8.1 and my platform toolset is 140.
I will begin configuring a release build next week after the new year.
Can anyone offer any suggestion?
If I may slip in a second question, do I need to worry about migrating DAO?
Thank you very much for any help that you can offer and have a Happy New Year.
SPC
S.P. Chapman
Digital Engineer
Radiant Technologies, Inc.
Albuquerque, NM.
radiant@ferrodevices.com
|
|
|
|
|
Your project is attempting to link to the old version of the MFC libraries (mfc80xxx). You need to edit the project properties to use the ones that come with VS2015. No idea about DAO, sorry.
|
|
|
|
|
As Richard said you are linking the lib files manually of which there are only three ways to do
1.) #pragma comment(lib, "mfc80d.lib") .. given you have searched for mfc80d.lib it can only be a macro name so just search for "#pragma comment". Something stupid like #pragma comment(lib, "mfc" _MFC_FILENAME_VER "d.lib")
2.) Under project properties Linker->Input->Additional Dependencies .. look for the name
3.) Under project properties Linker->command Line->Additional Options .. look for name (its usually blank)
Has to be in one of those 3.
daouuid.lib is an obsolete XP service pack 2 library file it wont be available in none XP builds. There is an XP build option on VS2015 it will probably link in that build.
In vino veritas
modified 31-Dec-16 9:14am.
|
|
|
|
|
I did, indeed, find "#pragma comment(lib, "mfc" _MFC_FILENAME_VER "d.lib")" in Afx.h under C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\atlmfc\include\afx.h. However, _MFC_FILENAME_VER is declared by:
#ifndef _MFC_FILENAME_VER
#define _MFC_FILENAME_VER "140"
#endif
in afxver.h.
I tried adding the declaration explicitly to the project StdAfx.h file but it made no change to the linker error. "#pragma comment" is not found anywhere in the project itself. There are no explicit references to MFC 80 in the linker settings.
Once I get a few beginning of the year things cleaned up, I am going to try a release build.
As for DAO, I am no longer targeting XP or Vista. I will need to fight that battle once I win this one.
Thanks for your advice. I will continue to tilt at this as I may, but I may be stuck with VS2005 compilations for some time.
Happy New Year to you.
FF
|
|
|
|
|
The simpler way is simply delete all the project and solution files and set them up from scratch using the create project from existing code option on the menu
In vino veritas
|
|
|
|
|
Yes, I am just about to that point. I have been redirecting my energies the past week or so, so I haven't had at this problem very much. I was actually considering moving the older library files into the project just to get things to link. I haven't tried a release build, yet, but if the release build does not link, moving the older files may resolve the problem but then cause a distribution nightmare, requiring 2005 and 2015 manifests. A new project with old code and resource files is a much better approach.
Thanks for your time
SPC
|
|
|
|
|
If any of your projects links another 3rd party library, that library, too, needs to be compiled with VS2015 - otherwise it will attract old MFC libs.
There's a very useful tool called depends that can show for each executable or dll what other binaries it depends on. You can use it to locate the dependency path that is responsible for attracting mfc80.dll. See Dependency Walker (depends.exe) Home Page[^]
GOTOs are a bit like wire coat hangers: they tend to breed in the darkness, such that where there once were few, eventually there are many, and the program's architecture collapses beneath them. (Fran Poretto)
|
|
|
|
|
Hi Stefan...
Thanks for the observation. And yes, I have been pursuing this same line. I am having trouble getting a reply from the the third party vendor. Meanwhile, other matters have pushed this to the side, so I haven't been giving it a lot of attention.
I will leave this reply up for the weekend, then remove/resolve this message.
Thanks again and have a great weekend.
SPC
|
|
|
|