A function that refuses to run anywhere else but main()


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 1 Week Ago
A function that refuses to run anywhere else but main()

Hi. I have some code, that for some reason, I could not post it here in this post. Here's the address for it:

#if 0 shc Version 4.0.1, Generic Shell Script Compiler GNU GPL Version 3 Md - Pastebin.com

First off, I used "shc" to convert the code from shell script to C.
And The problem is, I cannot call
Code:
menu()

from anywhere but,
Code:
main()

The error code I get while trying to call this function is this:

Code:
./test22 terminated by signal SIGSEGV (Address boundary error)

I want to call it from within a case statement, like this:


Code:
case 100: // alt-d
     menu();
     break;

I know, that it is a big "NO NO" to use code that is generated by a source code converter, but, i'd rather not use the shell script in my code, just standard C code. So, that is my reasoning for that. Maybe that's the problem right there?

I hope i'm being verbose enough in this post.


Thanks for your time. Any help is appreciated.
# 2  
Old 1 Week Ago
Quote:
Originally Posted by ignatius
I know, that it is a big "NO NO" to use code that is generated by a source code converter, but, i'd rather not use the shell script in my code, just standard C code. So, that is my reasoning for that. Maybe that's the problem right there?
Source code converters are OK, in and on themselves, but the problem begins when you try to edit the generated code. Code created by a generator is usually understandable only to the compiler - most likely even the generator is confused reading what it has produced. You don't create an assembler listing from compiled code and change that in assembler either (at least not as long hell is not overbooked and you are sentenced to doing this for your sins instead).

Let us take a step back: what is the reason you don't want to use a shell script? Maybe there is a way to solve this problem without using this abomination in what C was never intended to look like.

I hope this helps.

bakunin
# 3  
Old 1 Week Ago
I'd rather keep the code neat and tidy, so to speak. Using a shell script in the code is problematic.. for me. It's just ugly, IMO.


Thanks for the quick response.
# 4  
Old 1 Week Ago
Quote:
Originally Posted by ignatius
I'd rather keep the code neat and tidy, so to speak. Using a shell script in the code is problematic.. for me. It's just ugly, IMO.
OK, i can understand that. But why would you want to incorporate a shell script (or its C equivalent) into a C program in first place? What is the script supposed to do that the program can't do? Sorry, but i am confused.

bakunin
# 5  
Old 1 Week Ago
Simply because I can't write the code on my own... The shell script does everything that I need it to do, and saves me time by not having to write the code. I'm still a newb at C. Smilie
# 6  
Old 1 Week Ago
If you have a working shell script that you think is ugly, why don't you show us that ugly shell code. Maybe we can help you make it pretty or, at least, less ugly. Smilie
# 7  
Old 1 Week Ago
Actually, i'd prefer to use it in its C format, first. If I can't do that, then i'll fall back to using the shell script. Thank you for the offer, though. It's appreciated.
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
A single statement without main function in c techmonk Programming 2 08-03-2015 10:10 PM
[ksh93+] Array fed by function is empty when used in main. bibou25 UNIX for Dummies Questions & Answers 5 06-28-2013 02:48 PM
Calling functions from main program from dlopened library function syedtoah AIX 1 12-18-2012 03:19 PM
Function main returning int? gabam Programming 5 11-06-2012 08:04 PM
Unable to run function Subbeh Shell Programming and Scripting 18 08-30-2012 11:25 AM
Main script triggers second and it has to run at specific interval aditya206 Shell Programming and Scripting 0 05-14-2012 10:12 AM
How to access argv[x] from another function other than main??? gabam Programming 2 12-19-2011 09:28 AM
unable to send a char parameter from main to a function bluetxxth Programming 8 10-13-2011 01:45 PM
Help in separating variables declared in the main function abk07 Shell Programming and Scripting 1 06-12-2011 05:22 AM
Run function from script over ssh (BASH) columb Shell Programming and Scripting 1 05-28-2009 02:07 PM
signal handling while in a function other than main Theju Programming 1 09-18-2008 04:06 PM
main function arun.viswanath Programming 6 03-07-2008 11:43 AM
want to run a function in background bankpro Programming 5 02-01-2006 02:54 AM
Script to do a function on all files in one run Reza Nazarian Shell Programming and Scripting 5 10-01-2003 07:52 AM
c++ calling main() function norsk hedensk Programming 3 01-22-2003 07:28 PM