Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Variable is declared wrong type in emitted code #582

Open
zfi opened this issue Apr 22, 2021 · 0 comments
Open

Variable is declared wrong type in emitted code #582

zfi opened this issue Apr 22, 2021 · 0 comments
Labels
bug Something isn't working needs discussion Issue that requires further refinement before any code changes

Comments

@zfi
Copy link
Contributor

zfi commented Apr 22, 2021

In the example project below, the objective is to cause the terminal to emit a beep sound five times. In testing this project, the terminalBell variable is assigned a character value of decimal 7, the ASCII bell character. The compiler issues a warning about not casting an int value but we're not using a int value here. Except that we actually are.

2021-04-22_12-07-48

Compile... Succeeded.single.c: In function 'main':
single.c:16:5: warning: passing argument 1 of 'print' makes pointer from integer without a cast [enabled by default]
/opt/parallax/simple-libraries/Learn/Simple Libraries/TextDevices/libsimpletext/simpletext.h:309:5: note: expected 'const char *' but argument is of type 'int'

The code emitted from this project creates the terminalBell variable as an integer, even though the intent was for it to represent a character.

// ------ Libraries and Definitions ------
#include "simpletools.h"

// ------ Global Variables and Objects ------
int terminalBell;



// ------ Main Program ------
int main() {

  terminalBell = (7);
  for (int __n = 0; __n < 5; __n++) {
    print("Hello");
    print("\r");
    print(terminalBell);
    print("\r");
    pause(1000);
  }
}

If the first block is disabled and the second block is enabled, the project is now explicitly declaring the terminalBell variable as a character array and the ASCII bell character is being explicitly converted to a character.

2021-04-22_12-09-24

// ------ Libraries and Definitions ------
#include "simpletools.h"

// ------ Global Variables and Objects ------
char  terminalBell[64];



// ------ Main Program ------
int main() {

  sprint(terminalBell, "%s%d", " ", 7);
  for (int __n = 0; __n < 5; __n++) {
    print("Hello");
    print("\r");
    print(terminalBell);
    print("\r");
    pause(1000);
  }
}

It seems that the variable declaration should be based on how it is used but that is not happening here.

PlayBeep.svg.zip

@zfi zfi added bug Something isn't working needs discussion Issue that requires further refinement before any code changes labels Apr 22, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs discussion Issue that requires further refinement before any code changes
Projects
None yet
Development

No branches or pull requests

1 participant