Primitive c questions

Dear all,
I am starting writing some c code and I have gathered few primitive questions that I would like to ask.
Could you please spend some time helping me?

  1. I found that one can get information about basic c function from linux bash with man… Well I have to admit that I did not expect that. I thought that the man is only related to the bash linux only. Where it gets the information for the the c libraries. How it distingushes between c and bash commands?

  2. I have found in my c document a text about macros. What is a macro? Is for example the sizeof myvariable a macro? Where these are declared?

  3. IF i have a struct lets call it mystruct and then I do memset(&mystruct,0, sizeof mystruct) this will set to zeros all the variables inside of the struct, regardless what type of variables it includes. Is not that right?

I would like ot thank you in advance for your help
Regards
Alex

From here (Index of /pub/linux/docs/man-pages). You can get a man page for anything, nothing says it has to be related to bash.

The text should explain…

Technically no. In practice sure, use that for structs in dynamic memory.

On 2012-04-16 18:07, alaios wrote:

> 1) I found that one can get information about basic c function from
> linux bash with man… Well I have to admit that I did not expect that.
> I thought that the man is only related to the bash linux only. Where it
> gets the information for the the c libraries. How it distingushes
> between c and bash commands?

It doesn’t :slight_smile:

You just tell ‘man’ a name, it finds a match and you read it.

However… if you do “man man” you will see that there are several types of
manuals differentiated by numbers, and several of those numbers apply to c
libraries or functions. For example:

cer@Telcontar:~> man printf
Man: find all matching manual pages (set MAN_POSIXLY_CORRECT to avoid this)

  • printf (1)
    printf (3)
    printf (1p)
    printf (3p)
    Man: What manual page do you want?
    Man: ^C

The ‘1’ refers to the command used by the shell, but the 3 refers to the
“Linux Programmer’s Manual”, 1p and 3p to posix.

There are other languages: 3pm is for perl things, for instance.

> 2) I have found in my c document a text about macros. What is a macro?
> Is for example the sizeof myvariable a macro? Where these are
> declared?

I think they are declared in header files.

C “encoding” is done in two steps. One is the preprocesor pass, which
expands the preprocesor tokens, given with the “#” symbol at the start of a
line, and then expands them in the “text”. The second pass (or more (?))
are the compiler passes.

At least that is what they told me time ago :slight_smile:

Some words you use in C are actually macros defined in some header and
later expanded every time they are found.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

As on version 4.2x, only 4 (among hundreds) manual pages are related to bash: man bash, man bashbug, man bashbuiltins and man rbash. But bash has a builtin command named ‘help’, which provides info about other Bash builtin commands.

On 2012-05-02 05:16, please try again wrote:
>
> alaios;2456458 Wrote:
>>
>> 1) I found that one can get information about basic c function from
>> linux bash with man… Well I have to admit that I did not expect that.
>> I thought that the man is only related to the bash linux only
>
> As on version 4.2x, only 4 (among hundreds) manual pages are related to
> bash: man bash, man bashbug, man bashbuiltins and man rbash. But bash
> has a builtin command named ‘help’, which provides info about other Bash
> builtin commands.

You are right. We must not confuse “external” commands with “internal”
commands, or bash builtins. Or any other shell builtins.


Cheers / Saludos,

Carlos E. R.
(from 11.4 x86_64 “Celadon” at Telcontar)

sizeof is a unary operator like ~, ++, --, etc…

As for question #2:

A macro is a fragment of code which has been given a name. It is processed by the C preprocessor.

As a starting point read this: Macros - The C Preprocessor