How to build your own library of functions

Source: Internet
Author: User
Tags command line mathematical functions

Methods and applications of custom function libraries:

One, 2 related commands 1, TCC--TC DOS command line compiler connection Tool 2, TLIB--TC DOS Library operation tool

Two, a custom function library example

1, in the TC Integration Environment, the compilation of a file useradd.c

#define _NO_MAIN
int add(int *a,int *b)
{ int c;
c=(*a)+(*b);
return c;
}

Build a Useradd by ALT-F9 compilation. Obj file.

2, press F10-f-o to retreat to Dosshell (DOS environment)

COPY Useradd. OBJ to.. \lib directory, executing in \lib directory

Tlib Userlib. Lib+useradd. OBJ generates a library of its own userlib, which contains the binary code of the function module int add (int *a,int *b). Now that the custom function has been put into the function library, you can delete the original file USERADD.C. (Of course, in order to maintain convenience later, or make a backup as well). Later, if you have other function modules, you can also compile the tlib command to join the library.

3, write a file containing USER1. H, copy to the Include directory when you finish writing. The contents are as follows:

int add (int *,int *);

4, made the above custom function library preparation work, now can use.

Write a program named ADD-1.C, call the library function add () in the program;

#include<stdio.h>
#include<user1.h>
void main( )
{
int a,b,c;
a=20;b=30;
c=add(&a,&b);
printf(“%d”,c);
}

5, in the DOS command line, the implementation of TCC ADD-1. C.. \lib\userlib. LIB is ok!

Run Add-1.exe, you can see output 50

=============================================================

Note: Compiling and connecting in DOS is a hassle, and the following methods can be compiled and connected in a TC integrated environment.

In the second step above, the execution of the Tlib command is changed to Tlib CS. Lib+useradd. OBJ This is to add the binary code of the custom function module to the Run-time Library CS. Lib inside. (corresponding to the different compilation mode, choose different Cx.LIB)

Then compile the connection ADD-1 in the integrated environment. C is OK.

Note: CS.LIB Small mode Library

Cc. LIB Compact Mode Library

Cm. LIB Medium Pattern Library

Cl. LIB Large Mode Library

Ch. LIB Macro Mode Library

(The above five are run-time libraries that connect these libraries regardless of which program is established)

emu| Fp87:emu is a floating-point simulation function library, while FP87 is a floating point function library that is used when we have the 80x87 processor. If you have floating-point operations in your program, you must connect one of these two function libraries, and the MATHX function library.

MATHX: A library of mathematical functions. where x represents S, C, M, L, h characters.

In addition, the binary of which library function of TC is placed in which function library is unknown. But one thing is for sure, right here in the library.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.