PUBLIC void delset(set)
SET *set;
{
/* Delete a set created with a previous newset() call. */
if(set->map != set->defmap)
free(set->map);
free(set);
}
Müssen Sie immer eine Return-Anweisung in einer c-Funktion haben? Die obige Funktion gibt die folgende Warnung aus. Beachten Sie, dass ich keine Rückgabeerklärung habe.Ist in einer c-Funktion immer eine Return-Anweisung notwendig?
src/tools/set.c: In function ‘delset’:
src/tools/set.c:41:1: warning: control reaches end of non-void function [-Wreturn-type]
}
^
Sobald ich hinzufügen, die return 0;
die Warnung geht weg. Ich erhalte die Warnung auch wenn ich return;
PUBLIC void delset(set)
SET *set;
{
/* Delete a set created with a previous newset() call. */
if(set->map != set->defmap)
free(set->map);
free(set);
return 0;
}
angeben nur ich bin mit gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4
bearbeiten
# define PUBLIC
Scheint, wie es nur ein Marker ist. Diese SO question scheint es besser zu erklären, als ich kann.
Ich entfernte den PUBLIC-Marker vor der Funktion und die Rückleitung am unteren Rand. Ich bekomme immer noch den gleichen Fehler.
typedef struct _set_
{
unsigned char nwords; /* Number of words in map */
unsigned char compl; /* is a negative true set if true */
unsigned nbits; /* Number of bits in map */
_SETTYPE *map; /* Pointer to the map */
_SETTYPE defmap[ _DEFWORDS ]; /* The map itself */
} SET;
Aufnahme der folgenden Header-Datei (debug.h
) war das Problem verursacht. Nicht sicher, welche Linie genau das verursacht hat.
#ifdef DEBUG
# define PRIVATE
# define D (x) x
#else
# define PRIVATE static
# define D (x)
#endif
# define PUBLIC
#ifdef MSDOS
# define MS(x) x
# define UX(x)
# define ANSI
# define _8086
#else
# define MS(x)
# define UX(x) x
# define O_BINARY 0 /*no binary input mode in UNIX open() */
typedef long time_t; /* for the VAX, may have to change this */
typedef unsigned s1ze_t; /* for the VAX, may have to change this. Renamed the type as s1ze_t as stdio.h contains a type of the same name */
extern char *strdup(); /* You need to supply one. */
#endif
#ifdef ANSI /* If ANSI is defined, put arg lists into */
# define P(x) x /* function prototypes. */
# define VA_LIST ... /* and use ellipsis if a variable number of args */
#else
# define P(x)() /*Otherwise, discard argument lists and translate*/
# define void char /* void keyword to int. */
# define VA LIST _a_r_g_s /* don't use ellipsis */
#endif
/* SEG (p) Evaluates to the segment portion of an 8086 address.
* OFF (p) Evaluates to the offset portion of an 8086 address.
* PHYS (p) Evaluates to a long holding a physical address
*/
#ifdef _8086
# define SEG(p) (((unsigned *)&(p)) [1])
# define OFF(p) (((unsigned *)&(p)) [0])
# define PHYS(p) (((unsigned long)OFF(p)) + ((unsigned long)SEG(p) << 4))
#else
# define PHYS(p) (p)
#endif
/* NUMELE (array) Evaluates to the array size in elements
* LASTELE(array) Evaluates to a pointer to the last element
* INBOUNDS(array,p) Evaluates to true i f p points into the array.
* RANGE(a,b,c) Evaluates to true i f a <= b <= c
* max(a,b) Evaluates to a or b, whichever is larger
* min (a, b) Evaluates to a or b, whichever is smaller
*
* NBITS (type) Returns number of bits in a variable of the indicated
* type;
* MAXINT Evaluates to the value of the largest signed integer
*/
#define NUMELE(a) (sizeof(a)/sizeof(*(a)))
#define LASTELE(a) ((a) + (NUMELE(a)-1))
#define TOOHIGH(a,p) ((p) - (a) > (NUMELE(a) - 1))
#define TOOLOW(a,p) ((p) - (a) < 0)
#define INBOUNDS(a,p) (!(TOOHIGH(a,p) || TOOLOW(a,p))
#define _IS(t, x) (((t)1 << (x)) != 0) /* Evaluate true if the width of a */
/* variable of type of t is < x. The !=0 */
/* assures that the answer is 1 or 0 */
#define NBITS(t) (4 * (1 + _IS(t, 4) + _IS(t, 8) + _IS(t,12) + _IS(t, 16) + _IS(t,20) + _IS(t,24) + _IS(t,28) + _IS(t,32))
#define MAXINT (((unsigned)~0) >> 1)
#ifndef max
# define max(a, b) (((a) > (b)) ? (a) : (b))
#endif
#ifndef min
# define min(a,b) (((a) < (b)) ? (a) : (b))
#endif
#define RANGE(a,b,c) ((a) <= (b) && (b) <= (c))
Was ist 'PUBLIC'? – alk
Wie sieht die Ausgabe des Vorprozessors aus? – alk
Es ist notwendig für nicht-leere Funktionen. Wenn die Funktion keinen Wert zurückgeben soll, deklarieren Sie sie als "void". Dann kann die Steuerung das Ende der Funktion erreichen, ohne dass es ein Fehler ist (und Sie können auch leere 'return' Anweisungen verwenden). Wenn die Funktion nicht "falsch" ist, sollte sie immer einen Wert zurückgeben. –