Learning C - I get error message | conflicting types for ‘malloc’ (solved)

For discussions about programming, and for programming questions and advice


Moderator: Forum moderators

Post Reply
User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Learning C - I get error message | conflicting types for ‘malloc’ (solved)

Post by cobaka »

Hello all & woof.

I am learning C - a beginner.
Compiler in use: gcc - as supplied in uPupBB32.
Reference manual on hand: The GNU C programming manual. (The text is informative, but the encoding does not allow me to ctrl+f 'search' so it's a bit of a dog to find specific info.

BTW - the C source is (probably from) source forge. I didn't write the code.
It is an assembler, written in C.
Maybe I am biting off more than I can chew, but there is no better way to learn than to bash one's head against a wall.

The error message: as68_tst.c:11:7: error: conflicting types for ‘malloc’

Code: Select all

#include	"as68.h"

char *malloc(),*strcpy(),*strcat();     <--<< this is line #11 in as68_tst.c

#define	MAXOPTIM	2000

In 'err-list' (the error file) I read: In file included from as68_tst.c:8:0:
/usr/include/stdlib.h:539:14: note: previous declaration of ‘malloc’ was here
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;

and in /usr/include/stdlib.h on line 539 I see:

Code: Select all

/* Allocate SIZE bytes of memory.  */
extern void *malloc (size_t __size) __THROW __attribute_malloc__ __wur;
/* Allocate NMEMB elements of SIZE bytes each, all initialized to 0.  */
extern void *calloc (size_t __nmemb, size_t __size)
     __THROW __attribute_malloc__ __wur;

My guess: I am declaring the pointer twice, yes?
Another guess The syntax demanded by the original source has a few differences from the syntax demanded by the gcc compiler.

Help!

cobaka.

Last edited by cobaka on Tue Jul 19, 2022 7:19 am, edited 1 time in total.

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

User avatar
Keef
Posts: 250
Joined: Tue Dec 03, 2019 8:05 pm
Has thanked: 3 times
Been thanked: 67 times

Re: Learning C - I get error message | conflicting types for ‘malloc’

Post by Keef »

I'm no C programmer, but do like to compile things. This might just be very old code. See here:
https://stackoverflow.com/questions/477 ... for-malloc

User avatar
cobaka
Posts: 521
Joined: Thu Jul 16, 2020 6:04 am
Location: Central Coast, NSW - au
Has thanked: 87 times
Been thanked: 49 times

Re: Learning C - error message | conflicting types for ‘malloc’ (solved)

Post by cobaka »

Well @Keef you are spot on.

The source code (as09.c) I have is K&R standard but the 'Puppy' gcc compiler is more recent.

# gcc --version
gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Copyright (C) 2017 Free Software Foundation, Inc.

I will modify the source code I have (I guess this means learning the 'rules' for modifying open source) to meet a more recent standard.
I see the most recent standard is c18.
Since I am learning C - this will be a valuable exercise for me.

I'm not surprised that the code dates from an earlier time.
The 6809 was 'passe' before it came out of the silicon foundry.
Yes, 'passe' but the best 8-bit general purpose uP ever. Or maybe the CMOS 6309
The 68HC11 was also a very elegant chip. More 'on-board' features, but lacks some features found in the '09 e.g. a user stack.
But I'm off-topic.

I will mark this thread 'solved'

собака

собака --> это Русский --> an old dog
"so-baka" (not "co", as in coast or crib).

Post Reply

Return to “Programming”