Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Confusion in macro

Tags:

The following code works fine

#define open {
#define close }
#include<stdio.h>
#define int char

 main()
 open
 int a ;
 printf("This is testing code" );
 close

But If I exchange the lines

#include<stdio.h>
#define int char 

as

#define int char 
#include<stdio.h> 

it throws lot of errors like this

In file included from /usr/include/stdio.h:36,
                 from print.c:19:
/usr/include/bits/types.h:35: error: both 'short' and 'char' in declaration specifiers
/usr/include/bits/types.h:37: error: both 'long' and 'char' in declaration specifiers
/usr/include/bits/types.h:42: error: both 'short' and 'char' in declaration specifiers
/usr/include/bits/types.h:43: error: both 'short' and 'char' in declaration specifiers
.................................................
so and so 

Actually what is happening inside stdio.h ?

like image 437
abubacker Avatar asked Dec 03 '25 11:12

abubacker


1 Answers

There are defined variables of type short int, long int and so on, which obviously fails when you change them through define to short char and long char.

Redefining basic C types is usually not a good idea.

like image 147
Michal Čihař Avatar answered Dec 10 '25 01:12

Michal Čihař