Project

General

Profile

Actions

Bug #5958

open

rpc/xdr.h forces stdio.h on you

Added by Gordon Ross over 8 years ago. Updated over 8 years ago.

Status:
New
Priority:
Normal
Assignee:
-
Category:
-
Start date:
2015-05-27
Due date:
% Done:

0%

Estimated time:
Difficulty:
Medium
Tags:
needs-triage
Gerrit CR:
External Bug:

Description

rpc/xdr.h needs the stdio FILE typedef, which it gets by including stdio.h
It would be better if it included stdio_tag.h but that means finding all the
code that assumes rpc/xdr.h pulls in stdio.h and fixing it.

Actions #1

Updated by Gordon Ross over 8 years ago

  • Description updated (diff)
Actions #2

Updated by Marcel Telka over 8 years ago

Why it would be better to include stdio_tag.h instead of stdio.h to get the FILE?

BTW, I do not see the FILE defined in stdio_tag.h.

Actions #3

Updated by Gordon Ross over 8 years ago

The reason for stdio_tag.h is for libraries that want to define a function as accepting an arg of type FILE, i.e. for an output formatting function. In the rpc/xdr.h case we want FILE for xdrstdio_create.

The way to do this without forcing a stdio.h include on programs including rpc/xdr.h is either of:

1: Anonymous struct:

struct __FILE;
extern void   xdrstdio_create(XDR *, struct __FILE *, const enum xdr_op);

2: Use stdio_tag.h

#include <stdio_tag.h>
extern void   xdrstdio_create(XDR *, struct __FILE *, const enum xdr_op);

Lots of places in our system use the first method.
The second method is more standard (I think).

Here's a little C module demonstrating the two methods. (cc -c demo.c)


typedef struct _XDR XDR;
enum xdr_op { a, b };

#if 0 /* either of these work */
struct __FILE;
#else
#include <stdio_tag.h>
#endif

extern void   xdrstdio_create(XDR *, struct __FILE *, const enum xdr_op);

void
xdrstdio_create(XDR *x, struct __FILE *f, const enum xdr_op op)
{
}

Actions

Also available in: Atom PDF