How to access a C function from a shell script?


 
Thread Tools Search this Thread
Top Forums Programming How to access a C function from a shell script?
# 1  
Old 08-09-2016
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?
# 2  
Old 08-10-2016
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.
This User Gave Thanks to Don Cragun For This Post:
# 3  
Old 08-10-2016
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
# 4  
Old 08-10-2016
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.
This User Gave Thanks to Don Cragun For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script to pass the config file lines as variable on the respective called function on a script

I want to make a config file which contain all the paths. i want to read the config file line by line and pass as an argument on my below function. Replace all the path with reading config path line by line and pass in respective functions. how can i achieve that? Kindly guide. ... (6 Replies)
Discussion started by: sadique.manzar
6 Replies

2. Shell Programming and Scripting

Except script to run a local shell script on remote server using root access

local script: cat > first.sh cd /tmp echo $PWD echo `whoami` cd /tmp/123 tar -cvf 789.tar 456 sleep 10 except script: cat > first #!/usr/bin/expect set ip 10.5.15.20 set user "xyz123" set password "123456" set script first.sh spawn sh -c "ssh $user@$ip bash < $script" (1 Reply)
Discussion started by: Aditya Avanth
1 Replies

3. Shell Programming and Scripting

What is the function of the following lines at the top of a shell script file: Directory and Script?

The file starts like this: Directory: <path to the script> Script: <script fife name> #!bin/ksh ##Comments <actual script> What is the use of the first two lines in the script? What if I save the file without them? What will be the effect? They are not comments. Im very new to this,... (4 Replies)
Discussion started by: remytom
4 Replies

4. Shell Programming and Scripting

Shell Script function to use script name for log file output

Hi Team - I"m very new to Shell Scripting so I have a rather novice question. My forte is Windows Batch Scripting so I was just wondering what the Shell Script equivalent is to the DOS command %~n? %~n is a DOS variable that dispayed the script name. For instance (in DOS): REM... (11 Replies)
Discussion started by: SIMMS7400
11 Replies

5. Shell Programming and Scripting

Call a function in shell script from another shell script

I've 2 shell scripts viz., CmnFuncs.ksh and myScript.ksh. 1st script contains all common functions and its code is as below: $vi CmnFuncs.ksh #!/bin/ksh RunDate() { .... .... export Rundt=`date +%Y%m%d` } 2nd script is invoking the above one and I expect to use the RunDt variable... (8 Replies)
Discussion started by: njny
8 Replies

6. Red Hat

how to call a particular function from one shell another shell script

please help me in this script shell script :1 *********** >cat file1.sh #!/bin/bash echo "this is first file" function var() { a=10 b=11 } function var_1() { c=12 d=13 (2 Replies)
Discussion started by: ponmuthu
2 Replies

7. Shell Programming and Scripting

access db2 from shell script

How to connect to db2 through shell script using cygwin? (0 Replies)
Discussion started by: supriyat
0 Replies

8. Shell Programming and Scripting

SHELL SCRIPT Function Calling Another Function Please Help...

This is my function which is creating three variables based on counter & writing these variable to database by calling another function writeRecord but only one record is getting wrote in DB.... Please advise ASAP...:confused: function InsertFtg { FTGSTR="" echo "Saurabh is GREAT $#" let... (2 Replies)
Discussion started by: omkar.sonawane
2 Replies

9. Shell Programming and Scripting

Shell Script Function

Dear Friends, I am on SOLARIS 9 (ksh) I am working on a shell script that upload files with NcFTP with resume option. So far the script is working correctly. The script makes a list of files that need to be transferred and then launch the NcFTP command to start the transfer. ... (0 Replies)
Discussion started by: Aswex
0 Replies

10. Shell Programming and Scripting

getting the value of a c function in shell script

Let say there is a module fileselection module written in c language which returns the file name. Is it possible to get the file name from the file selection module directly, I mean can we call a c function directly in shell script without doing executable. If possible then how it can be... (1 Reply)
Discussion started by: surjyap
1 Replies
Login or Register to Ask a Question