Basic Software Interface Question

JC0724

Weaksauce
Joined
Oct 11, 2008
Messages
105
I have taken a few computer science classes(intro class to Java and C++, a data structure class teaching OOP principles, and fundamental programming languages class that focuses on LISP scheme, Prolog and C++) so I know I have a long way to go.

I have also taken a logic design class where I had to design a micro processor and an assembly language class.

I am trying to understand how does software code interface with other software or hardware?

So far most of my programming projects I have written them in Microsoft Visual C++ and Eclipse.

How would I go about taking in other code to interface with my code?
 
How would I go about taking in other code to interface with my code?

It depends on what you're asking. What do you mean by interfacing code with your code?

The easiest thing I can think of is libraries. If you want to do Fast Fourier Transform on a vector of data, for example, and somebody has already written code to do FFT, you could import their library. Their library exposes these things that are, believe it or not, called interfaces. An interface is a contract that tells you what functions/methods the library will provide for you. The interface tells you how to talk to the other code. I'd rather not provide you with a detailed explaination of how libraries work myself, because there's already plenty of information about them on the web, but I can point you towards the Wikipedia article or another page on the web.
http://en.wikipedia.org/wiki/Library_(computing)
http://mirrors.zoreil.com/webclub.kcom.ne.jp/ma/colinp/win32/dll/intro.html

If you have any specific questions, I could try to answer those. If you're asking how two running programs can talk to each other, that's a completely different and larger subject.
 
I am trying to understand how does software code interface with other software or hardware?

So far most of my programming projects I have written them in Microsoft Visual C++ and Eclipse.
Shared libraries, inter-process communication, web services, etc. If it is hardware communication, you would normally use a shared library that exposes contracts/interfaces for passing signals and alerting when a message is received.

How would I go about taking in other code to interface with my code?
I'd recommend looking at shared libraries, but also reading up on defining interfaces and the concept of contracts between endpoints.
 
Thank you, this makes a little more sense to me now.

I am just curious what, type of class would I take in my B.S for computer science where I will deal with .dll files/shared libraries or coding them?
 
Thank you, this makes a little more sense to me now.

I am just curious what, type of class would I take in my B.S for computer science where I will deal with .dll files/shared libraries or coding them?

That would depend upon what school you go to, but my guess would be you'd be most likely to encounter them in multimedia/graphics courses. To be honest, though, universities aren't really focused on things like using and creating libraries. Universities are focused on teaching you computer science (that's what your degree is in, after all), so don't be surprised if your school doesn't have any courses that involve libraries much.
 
I have another question, how does header files work in C or C++? Do they exist in Java?
 
Header files in C/C++ work via simple textual inclusion. The header file is 'physically' inserted at the point of declaration (the #include) by the preprocessor, such that its symbols can be referenced in the rest of the translation unit. Java uses a module-like system, I guess.

C++ will probably get some sort of standard module system sometime in the 2017 timeframe.
 
You haven't gotten a decent response yet in my opinion.

Software-hardware interactions can occur in a wide variety ways.

Many processors have load and store instructions which set and read the electrical values on one or more physical address/data bus(es) (often metal pins coming out of the processor). It is very typical for RAM to be physically connected to this bus so that you can save and retrieve values to the RAM. This is a hardware-software interaction.

More generally, non memory hardware can also be connected the address/data bus, and you can use load/store instructions to drive some desired electrical value to the device. This is known as memory-mapped IO.

As I mentioned though, there are many other ways for hardware and software to interact.
 
Header files in C/C++ work via simple textual inclusion. The header file is 'physically' inserted at the point of declaration (the #include) by the preprocessor, such that its symbols can be referenced in the rest of the translation unit.

...and in case you don't have much formal understanding of translation, the reason the for the header is so that the compiler can know what something is without loading it's entire definition.

When you compile a larger C++ program, each file is a 'translation unit', and the compiler works on each file one at a time. If you want to compile Cat.cpp, the compiler is only (aside from includes) looking at what is inside of Cat.cpp, and it will put that code together into compiled code in a file called Cat.o. If somewhere in Cat.cpp you're calling the function FoodDish::getFood(), and the function getFood is defined in FoodDish.cpp, when the compiler is working on Cat.cpp, it won't know anything about the getFood function. The compiler doesn't need to know how the getFood function works for Cat.cpp, though...It just needs to know how to talk to it...What arguments it takes and what it returns. Once it knows how to talk to getFood(), it knows how to build Cat.cpp so that it can talk to it. Later, after all the individual 'translation units' have been compiled, the linker will hook Cat.o and FoodDish.o together so that the program sees the cat trying to call getFood, it will know what to do when getFood() gets called. But when the compiler is making Cat.cpp, it only needs to know what arguments getFood takes and what type of response getFood returns, so we use a header file that contains only that information. That's why in a header file (FoodDish.h), you'll see something like Food * getFood(); and somewhere in the source file (FoodDish.cpp) you see the entire function, Food * getFood() { ... //do stuff ... }


Java uses a module-like system, I guess.

Right. Java has a unique qualified name to every class, no global functions and only one class per file, so-forth and so-forth, so when you reference a method or a class in Java, the compiler knows exactly what file to look in to find the definition (in C#, I'd imagine this is a bit more complicated thanks to things like partial classes, but I haven't looked at the source for C#'s compiler so I don't know how that works). Since Java knows exactly where to find what it is looking for, if it needs to find the method signature of a method (what arguments it takes and what it returns), it just looks it up in the original source file when it is referenced. It doesn't need to copy any code into the 'translation unit' it's working on because the information the compiler needs is so easy to find. And since it doesn't need to copy information into files the way C++ macros do, there's no real need to have condensed prototypes like what you'd put in a header file.

A note: Because of what I just said, the import command in Java doesn't actually do much. It just appends the full, qualified package path to the unqualified name if the item you're importing, so Timestamp would become java.sql.Timestamp, for example.
 
(in C#, I'd imagine this is a bit more complicated thanks to things like partial classes, but I haven't looked at the source for C#'s compiler so I don't know how that works)
The C# compiler merges all partial classes together into a singular class at compile time -- properties, methods/functions, attributes, etc. (details). The Intellisense in Visual Studio provides information on the summarized class at design time, and provides inline debug details if an aspect of one partial contradicts or duplicates an aspect within any of the other partials. Of course, compile-time errors would also reflect such issues.
 
Thanks guys, I really appreciate your responses/help.

For the most part I understood everything your wrote.

If you guys know of any good websites/books that I could read that would help me on these topics please let me know.

I am going to Google some of these topics and will post more questions if I have them in the future.
 
Back
Top