Q:

No compile error when function returns variable of wrong type

I have this C program.
#include <stdio.h>

unsigned char foo()
{
    int x = 1000;
    return x;
}

int main(int argc, char *argv[])
{
    printf("foo returns %d\n", foo());
}

I am using the following to compile it:
gcc -c -g -o ../tgt/Linux/main.c.o -Wall -fpic main.c
gcc ../tgt/Linux/main.c.o -g -o ../tgt/Linux/t -Wall

It generates the following output:
$ t
foo returns 232

This is the lower 8 bits of x in foo().  So, it makes sense. But my question is: why didn't this generate a warning and is there a way for me to generate warnings for this type of mistake?

A:

In the comment you mentioned :

I wonder why is in not triggered when both using -pedantic -Wall
  -Wextra.

-Wall doesn't turn  on the -Wconversion flag [1].
Neither -Wpedantic nor -pedantic would catch 
return x; // This is valid as per strict ISO C

In fact -pedantic would just check for any GNU C extensions [2].
For example if you compile below stuff:
int a=10;
int b[a]; // This is invalid as per strict ISO C

with -pedantic, gcc should give you :
 warning: ISO C90 forbids variable length array ‘b’ [-Wvla]

So the only option is to use -Wconversion explicitly while compiling.
gcc -Wconversion main.c -o main

