You are here:

C++/register int and VC++ DLL

Advertisement


Question
Hi David,

I have few questions on C and VC++.

(1) What is the difference between datatype "int" and "register int"?
   Is "int" by default set to "register"? Since "register int"
   increases the speed of loops, can I use them at all times, or there
   are limitations?

(2) I created a VC++ DLL (Win32 simple DLL), and I want to call its
functions from my MFC project. I tried __declspec, but not getting it
right still. Can you illustrate the steps comprehensively. I even read
articles on some site, but still not getting. How to use LoadLibrary(),either?

Regards,
Rohit

Answer
Rohit , Thank you for your question.

1. "register" is one of the keywords used to give a hint to the compiler as to how to generate code. In this case, you are asking the compiler to try to keep a variable in a register instead of in memory. Registers can be accessed much faster than memory locations. A compiler is free to ignore hints like "register". The limitation is that most CPUs have very few registers free for use by the program. If you mark ten variables as "register", it is possible that none of them will actually be assigned to a register. Probably one or two concurrent "register" variables will work on some host systems. It all depends. It is probably better to write speed-critical software in assembly language for the specific host CPU; then you have full control over variable allocation and program execution.

2. I regret that I am unable to write a guide for DLL programming because of the volume of questions received. If you have any specific questions, please do not hesitate to ask!

David Spector

C++

All Answers


Answers by Expert:


Ask Experts

Volunteer


David Spector

Expertise

Highly knowledgeable in the C++ language, Visual C++ (MSVC), Windows API, documentation and other quality-assurance techniques, and debugging. Knowledgeable in MFC, COM, GUI design, and object-oriented design.

Experience

I have been a software engineer since 1965. I have been published. My specializations have been: biomedical programming, compiler implementation, and many kinds of Windows programming. I don't do Databases or other business-oriented stuff.

Publications
Windows?/DOS Developer's Journal, ACM SIGPLAN Notices, and Computer Science Press.

Education/Credentials
ICCP Systems Programming Certification
Master's degree equivalent in Computer Science

©2016 About.com. All rights reserved.