this post was submitted on 14 Sep 2023
6 points (87.5% liked)
C Programming Language
936 readers
2 users here now
Welcome to the C community!
C is quirky, flawed, and an enormous success.
... When I read commentary about suggestions for where C should go, I often think back and give thanks that it wasn't developed under the advice of a worldwide crowd.
... The only way to learn a new programming language is by writing programs in it.
- irc: #c
🌐 https://en.cppreference.com/w/c
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
As far as I recall and for Linux, the shebang is interpreted by the kernel to execute the text file as the input of a given program. Are you talking about adding a shebang to a C source file? If so, this would not work, because the hash could be interpreted as a preprocessor instruction.
Take into consideration that, in bash, you can use ${0} to get the filename of the current script. If you want the count of lines in your script
wc -l ${0}
ought do the trick.If you're using C, you could rely on the FILE define for your imolementation but the rest implies reading the source code and then acting on it.
More Background might be helpful - I am writing an interpreter that will read and execute "keystroke programmable RPN calculator program"
The #! I am asking about will be in the text of the calculator program, it will cause the interpreter to be loaded.
My understanding is that after that the rest of the file of calculator program steps will be presented to the C program as standard input. But if that is the case, then I only see this input once and have no way to elicit a second pass through the code.
No, the #! is the input to an Interpreter that is written in C. The rest of the file is in "calculator language" (sort of like an HP41C but labels are merged with steps and variables take up one step each but are named so you can have as many as you like). The
I am not getting this, but anyway, I am writing an interpreter in C to run a program written in "Calculator Language"
What are you saying? I think that word was supposed to be "implementation", but what is a "FILE define"? The interpreter won't have the name of the file, will it?
One thing I might do is provide the name of the calculator language file in the shebang so the interpreter sees it..
This is the start of a file in calculator language named fizbuz.lnc :
#! /bin/lincalc fizbuz.lnc
The interpreter would see this first line on its standard input and stop reading standard input, and open the file "fizbuz.lnc" but this is non-standard for a shbang line. Also, this won't work if the shebang is stripped off the input by the shell and not provided to the called program.