Building own library

O

Owner

Can someone tell me how to build your own library properly

with portability and etc?

using #ifndef

thing like that.

I'm totally new to building own library.

thank you in advance
 
I

Ian Collins

Can someone tell me how to build your own library properly
with portability and etc?

Unfortunately there isn't a portable library format. Each platform has
its own 9ant often more than one).
 
S

Seebs

Can someone tell me how to build your own library properly
with portability and etc?

Let me give examples of comparable questions.

Can someone tell me how to run your own company properly
with legality and etc?

Can someone tell me how to design your own building properly
with safety and etc?

Can someone tell me how to raise children well with
good upbringing and etc?
using #ifndef

This should be one of your last resorts in building portable code.
I'm totally new to building own library.

You are not in a state of mind where you are likely to cease being new
at it, either.

-s
 
C

Chris H

Ian Collins <ian- said:
Unfortunately there isn't a portable library format. Each platform has
its own 9ant often more than one).

It depends he could mean a library of source code.
Also he does not say what he wants to be portable to...
Or what sort of thing he wants to be portable


The Librarian is one of the most under used resources in C in my
experience. A pity.
 
O

Owner

I wasn't specific enough. could someone point at some web
site? or write steps making static library? I googled but
no luck with answer that I wanted

2nd, I see sometimes macro with something like _prototype
I'm guessing they're doing it for portability. hope some-
one can tell me how to build library with _prototype macro.
or explain briefly what that _prototype macro used for

thank you
 
J

James Kuyper

For the #ifndef issue, I suspect that you're thinking of "include
guards" or "header guards". Wikipedia has some information:
http://en.wikipedia.org/wiki/Header_guard
(I haven't checked it for accuracy.)

I doubt it; I suspect he's referring to the use of #ifdef for various
feature-test macros. For instance, I've seen a lot of things like
#ifdef unix
or
#ifdef BIGENDIAN
etc.

The C standard provides a few macros that can be used to inquire about
implementation features, though for many of them, you #if would be more
appropriate than #ifdef:
* any macro #defined in <limits.h>, <float.h>, or <fenv.h>
* __STDC__
* __STDC_HOSTED__
* __STDC_MB_MIGHT_NEQ_WC__
* __STDC_VERSION__
* __STDC_IEC_559__
* __STDC_IEC_559_COMPLEX__
* __STDC_ISO_10646__
* You can determine whether any of the optional size-named types, like
int32_t is supported, by checking whether any of the associated macros,
from <stdint.h> or <inttypes.h>, such as INT32_MAX, is #defined.
* imaginary or _Imaginary_I
* math_errhandling
* __bool_true_false_are_defined

I gather that the next version of the standard will add several more
macros that can be tested to determine whether optional components of
the language/library are supported.

Except insofar as the relevant macros are defined by the C standard
itself, this approach quickly becomes unworkable once you want to port
to more than a few different systems.

The simplest approach to portability is to avoid using facilities of the
language or library that are implementation-specific, and to avoid
dependence upon implementation specific features of the facilities that
are universally available. It's generally not possible to avoid these
things completely, but you can isolated them in a small portion of your
code, so that only that code needs to
 
J

James Kuyper

I wasn't specific enough. could someone point at some web
site? or write steps making static library? I googled but
no luck with answer that I wanted

2nd, I see sometimes macro with something like _prototype
I'm guessing they're doing it for portability. hope some-
one can tell me how to build library with _prototype macro.
or explain briefly what that _prototype macro used for

Back in the days when C90 was new, and prototypes had just been
introduced, many people invented various macros to make it easier to
write code that would use prototypes on compilers that handled them
properly, but would also work properly on pre-standard compilers that
did not support them. By definition, there is no standard way of doing
this, because there's no standard way of determining whether a
pre-standard compiler is compiling your code. _prototype sounds like it
might be one of those macros, but you'll have to find out what is
#defining that macro before you can learn how to use it.

I would not recommend doing so. Pre-standard compilers are now more than
two decades out-of-date, it's pretty rare that anyone needs to write
code which must be portable to such implementations.
 
S

Seebs

I wasn't specific enough.

No, you weren't.
could someone point at some web
site? or write steps making static library? I googled but
no luck with answer that I wanted

And still aren't.

You haven't come close to explaining what it is that you want to do.
The answer is *probably* system-specific.

Questions you might have in mind:

* Do you want to design some code with intent that it be used
as a library?
* Do you want to know the mechanics of how to take code you've already
got and put it into a library file of some sort that can be linked into
many programs without being recompiled?
* Do you want to know something else entirely?

The problem here is that, so far as I can tell, you don't actually know
what "a library" is in enough detail to have any idea what you're asking
about. This is like having someone who's never looked at any kind of
medical text or studied anatomy ask how to go about "surgery".
2nd, I see sometimes macro with something like _prototype
I'm guessing they're doing it for portability. hope some-
one can tell me how to build library with _prototype macro.
or explain briefly what that _prototype macro used for

Who knows? "Something like _prototype" is pretty vague. You know, I heard
someone speaking Chinese, he used a word that sounded something like pling,
can someone tell me what it meant? The computer had a message on the screen,
it was something like there was a problem, what specifically did it mean
by that message?

I might be able to guess at this one just because it's a very common thing
in old code. Long ago, C used to declare functions like this:

float foo();

that meant "somewhere out there is a function called foo, which returns
a float".

Starting with C89, C allowed declarations like this:

float foo(int);

that meant "somewhere out there is a function called foo, which returns
a float, and takes a single argument which is an int". This new kind of
declaration is called a "prototype".

Since not all compilers supported these, people tended to do fancy stuff
like:

#ifdef __STDC__
#define P(x) x
#else
#define P(x) ()
#endif

float foo P((int));

This technique has been pretty much irrelevant to nearly everyone for,
I'd guess, 15+ years now. There are a few people who still have reason to
use it, but here's the thing: If you don't already know about it, *you are
not one of those people*.

This has *nothing* to do with portability in any modern sense.

-s
 
J

Jorgen Grahn

I wasn't specific enough. could someone point at some web
site? or write steps making static library? I googled but
no luck with answer that I wanted

(I was going to refer you to the Wikipedia article about static
libraries, but it seems completely crazy.)

There's no magic involved -- static libraries are just a bunch of
object files bundled together, and the linker treats such a library
pretty much like a bunch of object files. On Unix you use the ar(1)
command to create one. For example, from one of my Makefiles:

libprefer.a: citespec.o
libprefer.a: twinstate.o
libprefer.a: words.o
libprefer.a: version.o
$(AR) -r $@ $^
2nd, I see sometimes macro with something like _prototype
I'm guessing they're doing it for portability. hope some-
one can tell me how to build library with _prototype macro.
or explain briefly what that _prototype macro used for

Like someone else wrote, this is most likely old garbage from the 1980s.

There's nothing special you have to do in the source code to create a
static library. If you know how to split your program in separately
compiled source files, you know how to do libraries.

/Jorgen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,952
Messages
2,570,111
Members
46,695
Latest member
Juliane58C

Latest Threads

Top