How fix this compiler error? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 2

How fix this compiler error?

In the first lesson of pointers there's a code of locatios, the compiler displays an error in the moment that this code is runed How Can I fix this? Why is this happening?

22nd Mar 2020, 5:44 AM
Alan Villegas
Alan Villegas - avatar
8 Answers
+ 2
You said something that take my attention Sololearn still teach some old programming techniques that now they're not used because are a bad practice For example, in the firsts lessons, they explain the function "gets()" as a way to scan input to our programs But they don't say that the compiler will show an error and it's better use fgets() instead gets()
31st Mar 2020, 6:55 PM
Alan Villegas
Alan Villegas - avatar
+ 2
Yes, that is true. But apart from changes in standard (applied in compilers), maybe that was because the lessons were designed in such a way to be easy for those who were just getting started. There are more learning curves needed to keep up with the standard, and that *might* take the new learners aback because it looks and feels "difficult". If you visit this forum frequently enough you'll notice that some new learners still face difficulties even with the current state of the lessons. That is why I think we should notify SoloLearn about these types of cases. It is the way to let SoloLearn team know about it, so hopefully they can fix it soon, in order to prevent such doubts arising from the next generation of learners.
1st Apr 2020, 3:56 AM
Ipang
+ 1
Si, me refiero al uso de %x, me marca un error al momento de compilar
31st Mar 2020, 4:19 PM
Alan Villegas
Alan Villegas - avatar
+ 1
Perdón por mi ignorancia pero que se podría hacer para solucionar eso? Yo lo que hago ahora son dos posibles alternativas 1. En lugar de usar %x, utilizo %p 2. Declarar un apuntador que apunte a la dirección de memoria de una variable x, e imprimir de igual manera el puntero con el especificador de formato %p
31st Mar 2020, 4:37 PM
Alan Villegas
Alan Villegas - avatar
+ 1
"How can I fix this?" Because the warning is in "Try it yourself" example, I think best we (users) could do was to notify SoloLearn about this, through in-app Feedback feature or by sending e-mail. "Why is this happening?" The compiler is upgraded, but the lesson still uses previous standard where such things were still tolerable. SoloLearn server is 64bit machine, meaning pointers and addresses are 64bit integer. The %x format specifier was not meant for 64bit integer value, and the use of %x specifier to format a 64bit integer may risk improper result (or maybe undefined behaviour). I agree that the use of %p format specifier is a good idea to solve the problem as %p was designed as format specifier for pointers and addresses.
31st Mar 2020, 4:43 PM
Ipang
0
Do you mean the Sololearn C pointer lessons?
22nd Mar 2020, 5:52 AM
Eduard Arias
Eduard Arias - avatar
0
Bueno, acabo de mirar los códigos de esa lección y no marca error de compilación pero si un warning. Lo que pasa es que %x espera como parámetro un unsigned int, pero se le pasa la dirección de memoria de las variables que siempre serán tratadas como int. El warning nos dice que aunque no hay error podría ser mala práctica tratarlos como dos tipos iguales, pero que lo deja pasar
31st Mar 2020, 4:26 PM
Eduard Arias
Eduard Arias - avatar
0
Pues la solución más sencilla es cambiar el %x por %d, de esa manera no habrá warnings
31st Mar 2020, 4:38 PM
Eduard Arias
Eduard Arias - avatar