1

I am referring to GNU c tutorial it says assign non-integer value to integer variable will generate compile time error what exactly the error is,any example?? i tried

int a='A';

int a=2.323;

all are fine

what else could be to justify the statement??

1 Answers1

2

In some cases some conversions are being made. You can use -Wconversion in gcc for example to warn for implicit conversion.

(see Why assignment of double to int does not trigger gcc warnings?)

One example that does not compile is

struct account {
   int account_number;
   char *first_name;
   char *last_name;
   float balance;
};

struct account s;

int a=s;//breaks

The error message is in MSVC100 for example.

error C2440: 'initializing' : cannot convert from 'account' to 'int'

No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called

Community
  • 1
  • 1
Gabriel
  • 3,564
  • 1
  • 27
  • 49