Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

228
Views
GCC no advierte sobre conversión y pérdida de datos

Estaba jugueteando con GCC 4.9.2 en Windows y noté que no advierte sobre la conversión de doble a int, mientras que el compilador de Visual Studio sí lo hace:

El código:

 int main() { int celsius, fahrenheit, kelvin; celsius = 21; fahrenheit = celsius * 9 / 5 + 32; kelvin = celsius + 273.15; //here it should warn! printf("%d C = %d F = %d K", celsius, fahrenheit, kelvin); return 0; }

Compilé usando:

 gcc hello.c -Wall -Wextra -pedantic -std=c99

Compilé el mismo código con el compilador de Visual Studio:

 C:\temp>cl hello.c /nologo /W4 /FeC2f.exe hello.c hello.c(14): warning C4244: '=': conversion from 'double' to 'int', possible loss of data

¿Qué estoy haciendo mal?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debe usar el indicador -Wconversion , con eso gcc advierte:

 warning: conversion to 'int' from 'double' may alter its value [-Wconversion] kelvin = celsius + 273.15; //here it should warn!

¿Por qué no está habilitado con -Wall o -Wextra Está cubierto en el wiki vinculado que dice:

Las conversiones implícitas son muy comunes en C. Esto, junto con el hecho de que no hay flujo de datos en los front-ends (consulte la siguiente pregunta), da como resultado advertencias difíciles de evitar para un código válido y que funcione perfectamente. Wconversion está diseñado para un nicho de usos (auditorías de seguridad, portar código de 32 bits a 64 bits, etc.) donde el programador está dispuesto a aceptar y solucionar advertencias no válidas. Por lo tanto, no debe habilitarse si no se solicita explícitamente.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!