How to access a C function from a shell script?

Hi, I'm new to shell programming. And I'm having issues with accessing a C file with shell. Given a C code which contains functions and Lets say each function contains a multiplication instruction. [ a*b] So I need to extract the size of the operands (a,b) of each multiplication instruction in bits. How can I do this task? At least a clue please?

I fail to see how this thread is fundamentally different from the 1st question in your first thread: How to extract operand size in bits of a C program? nor why you believe that changing from an addition to a multiplication should cause a different answer than what you received in post #2 in that thread??? Is there some reason why you believe the answer I provided there is wrong?

I suppose if you really wanted to you could try to write a C language parser in a shell script to look for every multiplication operation in the C and assembler source files it is asked to process and instead of producing object code emits sizes of the types of the variables or constants being multiplied. And, if what you really want is the highest bit set in the results of each of those multiplications (as in the second question in your first thread), you would not only have to produce runnable object code, but also run them with real data and have your compiler add code to that object code that would print he highest bit set after each multiplication operation found in the source files you processed with your compiler.

I won't say it is impossible to do this, but shell is certainly not the language of choice for a project like this.

1 Like

I appreciate your help Don Cragun. And I followed your code and extracted the bit size of of operands of my C code. But I had to use snprintf() and system() functions to pass the variables from C code to shell. But the thing is I cannot pass variables from my C code, yet have to find each multiplication of an instruction and find the highest bit set of each operand. I thought this as a different question and moved to a new thread. Help me if you have an idea of doing this. Just the guidelines are enough. Yes I understand writing a shell script to do this task is quite annoying, but passing variables manually from C code has to be eliminated and the whole process should be done in a shell script. Thank you

I didn't say that writing a C compiler in shell was annoying; I said that shell is the wrong language to use to write a C compiler.

Of course, another option would be to write an emulator for the CPU and GPU you're using to execute the program you want to trace, trap the various multiplication instructions supplied by those chips, and capture the operands that those instructions will process. Again, the shell programming language is not a good choice for this project.

Your specifications for what you are trying to do are still extremely vague, but this is not the kind of major research project you are likely to find lots of volunteers in a forum like this to help you. If you produce a clear specification of what you're trying to do, show us that you have written a significant amount of code working towards you goal, and you get stuck on something, we'll be glad to help you get around your roadblocks. If you want us to design and write a project like this for you, I doubt that you'll find any volunteers here to do that for you.

I wish you good luck.

PS: Note that I also advised a friend about 35 years ago that COBOL wasn't a good language to use to write an operating system as a class project, but she did it anyway and got an A in the class. Note also that she was an expert in COBOL and had developed a detailed specification of exactly what that operating system was supposed to do.

1 Like