English 中文(简体)
职能和标题档案(单位:c)
原标题:Functions and header files (ansi c)

This is a question from job interview.Let s say we have "a.c" source file with some function and "a.h" as its header file.Also we have main.c file which calls that function.Now let s suppose we have "a.h" and "a.o"(object file) and a.c is unavailable.How do we call this function now? (I had a hint that we need to use function pointers.Another hint is to do this using pre-compiler directives such as #define and #ifndef). Also i would like to know how in .h file we know if we are linked properly to source file? Thank You

问题回答

仅包括主.c的一.h,你可以使用在一.h宣布的职能。 之后,仅将其汇编成一个编汇版。

gcc -c main.c
gcc main.o a.o

为了汇编主.c,你需要功能定义。 你们已经这样做了。 因此,你将写:

// main.c
#include "a.h"

int main()
{
    foobar(); // Let s say this is the function from a.h
}

在汇编时,你必须把物体档案列入连接阶段。 因此使用gcc......

gcc -c main.c // Compile main.c to main.o
gcc -o main main.o a.o

不需要任何职能点或宏观因素。

你们描述这种说法的方式,你只需要一份标题文件来说明这一功能。 标题文件载有该职能的原型,使汇编者能够知道该功能的签名是什么。

然后,你将链接到您的物体档案中(其中载有汇编的功能版本),一切都将是科索沃。

我不知道为什么你们需要职能点或公司前指令。 你们是否不理解问题100%?

在主.c中,这一职能称为正常职能。

然后汇编主.c至主.o.gcc -c main.c

然后将一线和主线连接起来。 <代码>gcc main.o a.o

对这一问题有点可笑。 你如何主要写上职能呼吁,完全取决于其声明。 存在或不出现某种情况就没有变化。 肯定不涉及宏观或职能点。

汇编和链接是两个不同的步骤;汇编者检查,你根据功能声明重新通过正确数目和种类的论据,并将结果分配给正确的类别物体,而链接者则试图解决在机码中提及功能的问题。

汇编和连接的结果是,与原始来源代码1可能或不可能有任何明显关系。 试卷保存了不同层次的信息,以支持来源层次的变错,但你可以完全依靠排放版本,而不是保护 任何<>>/em>有用的源信息。


1. Every now and again someone asks for a tool to recover source code from an executable; this is often described as attempting to turn hamburger back into cows.




相关问题
Fastest method for running a binary search on a file in C?

For example, let s say I want to find a particular word or number in a file. The contents are in sorted order (obviously). Since I want to run a binary search on the file, it seems like a real waste ...

Print possible strings created from a Number

Given a 10 digit Telephone Number, we have to print all possible strings created from that. The mapping of the numbers is the one as exactly on a phone s keypad. i.e. for 1,0-> No Letter for 2->...

Tips for debugging a made-for-linux application on windows?

I m trying to find the source of a bug I have found in an open-source application. I have managed to get a build up and running on my Windows machine, but I m having trouble finding the spot in the ...

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

Good, free, easy-to-use C graphics libraries? [closed]

I was wondering if there were any good free graphics libraries for C that are easy to use? It s for plotting 2d and 3d graphs and then saving to a file. It s on a Linux system and there s no gnuplot ...

Encoding, decoding an integer to a char array

Please note that this is not homework and i did search before starting this new thread. I got Store an int in a char array? I was looking for an answer but didn t get any satisfactory answer in the ...

热门标签