473,398 Members | 2,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

beginner's questions

Hi all,

I've started to program in C not long ago, and I've got some questions:
(I work on Linux 2.4.22/Debian)

1. Why the "**var" construct is used? What are the cases when it is
commonly needed? I'd like to read more about it, but there's nothing in
K&R on this theme, AFAIR.

2. Suppose, I want to see the source code of the "fopen" function used
by my system. Where do I have to look to learn it? Is it some header
file? (/usr/include/stdio.h contains only the pre-declaration of it) Is
it an OS-specific question?

3. Why is "___P" used in declaraion of functions like "main __P((int,
char *[]));"? What is the sense of it? Does using it have any pluses?
Where do I read about it (online, preferably)?

Thanks,
K.Gruzdnev

Nov 14 '05 #1
3 1427

gr******@gmail.com wrote:
Hi all,

I've started to program in C not long ago, and I've got some questions:
(I work on Linux 2.4.22/Debian)

1. Why the "**var" construct is used? What are the cases when it is
commonly needed? I'd like to read more about it, but there's nothing in
K&R on this theme, AFAIR.
What do you mean?
T **var;
declares var a pointer to a pointer to type T.
**var
yields a value of type T (if everything is correctly
initialised/assigned).
One example is
#include <stdio.h>

int main (int argc, char **argv)
{
char **p;
int i;

p = argv;

for (i=0; i<argc; i++, p++)
printf("%c\n", **p); /* print the first character of each
** parameter. */

return 0;
}
(Untested).

Another is:

char *p = NULL;
change_p (&p);

where change_p() has a char ** parameter.

2. Suppose, I want to see the source code of the "fopen" function used
by my system. Where do I have to look to learn it? Is it some header
file? (/usr/include/stdio.h contains only the pre-declaration of it) Is
it an OS-specific question?
The standard library functions often have to use system-specific,
non-portable code and often do use non-standard stuff for
speed-up. So, it depends on your compiler, library and OS.
I would indeed start with an OS-specific newsgroup or forum.

3. Why is "___P" used in declaraion of functions like "main __P((int,
char *[]));"? What is the sense of it? Does using it have any pluses?
Where do I read about it (online, preferably)?


Note that leading underscores belong to the implementation's namespace,
so the "___P" probably is something you have not to care about.
Probably it is a macro.
The way it is used, it could be a macro which provides C89 type
prototypes if __STDC__ is defined and K&R-C type function declarations
else. But these are just wild guesses.
Cheers
Michael
--
E-Mail: Mine is a gmx dot de address.

Nov 14 '05 #2
gr******@gmail.com wrote:
# Hi all,
#
# I've started to program in C not long ago, and I've got some questions:
# (I work on Linux 2.4.22/Debian)
#
# 1. Why the "**var" construct is used? What are the cases when it is
# commonly needed? I'd like to read more about it, but there's nothing in
# K&R on this theme, AFAIR.

Simulate pass by name.
int afgets(char **linevar,int size,FILE *fp) {
char *line = malloc(size);
if (fgets(line,size,fp)) {*linevar = line; return 1;}
else {free(line); *linevar = 0; return 0;}
}
...
char *line;
while (afgets(&line,20,stdin)) {
doWahDiddy(line); free(line);
}

Pointer chasing in linked lists. You'll need to draw some pictures to understand this
typedef struct T{struct T *link; int data;} T;

T *removeAll(T *head0,int data) {
T *head = head0; T **current = &head;
while (*current) {
if ((*current)->data==data) {
T *sacrafice = *current;
*current = sacrafice->link;
free(sacrafice);
}else {
current = &((*current)->link);
}
}
return head;
}

# 2. Suppose, I want to see the source code of the "fopen" function used
# by my system. Where do I have to look to learn it? Is it some header

Depends on your vendor. Some (like gnu) supply the source code, some don't.

# 3. Why is "___P" used in declaraion of functions like "main __P((int,
# char *[]));"? What is the sense of it? Does using it have any pluses?
# Where do I read about it (online, preferably)?

Probably somewhere it defines
#define __P(x) x
or
#define __P(x)

The first #define converts those declarations into ANSI-C function prototypes. The
second #define converts them into old style K+R function declarations. It lets you
use the same header file for two different styles of compilation.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
I have no idea what you just said.
I get that alot.
Nov 14 '05 #3
<posted & mailed>

gr******@gmail.com wrote:
Hi all,

I've started to program in C not long ago, and I've got some questions:
(I work on Linux 2.4.22/Debian)

1. Why the "**var" construct is used? What are the cases when it is
commonly needed? I'd like to read more about it, but there's nothing in
K&R on this theme, AFAIR.
**var is simply a pointer to a pointer to something.

2. Suppose, I want to see the source code of the "fopen" function used
by my system. Where do I have to look to learn it? Is it some header
file? (/usr/include/stdio.h contains only the pre-declaration of it) Is
it an OS-specific question?
You need to install the C library source code (in your case, GNU libc), if
available (in your case, it's available but you probably don't have it
installed). The header files contain no code, just macros, prototypes, and
data structures.

3. Why is "___P" used in declaraion of functions like "main __P((int,
char *[]));"? What is the sense of it? Does using it have any pluses?
Where do I read about it (online, preferably)?
___P is a macro. Check the header files for a definition for it.

Thanks,
K.Gruzdnev


--
Remove '.nospam' from e-mail address to reply by e-mail
Nov 14 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Atip Asvanund | last post by:
Dear sirs, I am trying to learn how to use Boehm's garbage collector: http://www.hpl.hp.com/personal/Hans_Boehm/gc/ on a Linux machine. I am a beginner, and I find its documentation inadequate....
7
by: Rensjuh | last post by:
Hello, does someone have / know a good C++ tutorial for beginnners? I would prefer Dutch, but English is also fine. Hoi, heeft / kent iemand nog een goede C++ tutorial voor beginners? Het liefste...
15
by: Pelle Beckman | last post by:
Hi all, I have a few newbie questions: In function declaration what does a 'const' mean inside the parameter list ? That it won't modify the value? void MemberFunction(const int x);
12
by: Sathyaish | last post by:
Please forgive my nescience. I have worked extensively on Win32 but I am only familiar with C and C++. Lately, I have been practicing C from K&R. Here 're a few doubts I have written in the...
27
by: MHoffman | last post by:
I am just learning to program, and hoping someone can help me with the following: for a simple calculator, a string is entered into a text box ... how do I prevent the user from entering a text...
3
by: GoCoogs | last post by:
Is there a beginner VB.NET newsgroup or forum? I don't want to make you all laugh or take up your time with my "two weeks into VB.NET" questions. Thanks a lot -Blake
6
by: Qun Cao | last post by:
Hi Everyone, I am a beginner on cross language development. My problem at hand is to build a python interface for a C++ application built on top of a 3D game engine. The purpose of this python...
1
by: Robert J. Bonn | last post by:
I'm trying to set up a contact list in MS Access 97. I've looked through a reference book and the program's help screens, but the light bulb isn't quite coming on for me. If one of you could take...
10
by: See_Red_Run | last post by:
Hi, I am trying to figure out how to get started with PHP/MySQL. Everything I've read so far says to start with PHP first. I was expecting something like Visual Basic Express or some other type...
22
by: ddg_linux | last post by:
I have been reading about and doing a lot of php code examples from books but now I find myself wanting to do something practical with some of the skills that I have learned. I am a beginner php...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.