subroutine

Determining subroutine argument evaluation order [duplicate]

陌路散爱 提交于 2019-12-20 04:23:56
问题 This question already has answers here : Why are these constructs using pre and post-increment undefined behavior? (14 answers) Closed last year . I am writing a program in C that determines the order in which subroutine arguments are evaluated. What I have so far is the following: int i=1; printf("%d %d %d\n", i++, i++, i); but I'm not sure If I am on the correct path or would it be easier to write in a different language like Ruby. How can I write a program in C (or Ruby) that determines

Subroutine with array element as argument

五迷三道 提交于 2019-12-20 03:30:26
问题 In my program subroutine stlstp passing work(2,1) as parameter to stlfts(...) subroutine. work(2,1) will be double value at that index, but how subroutine converting it as single dimension array x(n) ? When I print x value in stlfts(...) subroutine, it is printing elements of n size, example: STLFTS....X,,, 0.0000000000000000 1.4964418382246345E-317 1.48978578 58438612E-317 1.4964339331743010E-317 1.4964418382246345E-317 4.3367611401 .... My understanding is, except 1st value, all other

nasm calling subroutine from another file

て烟熏妆下的殇ゞ 提交于 2019-12-19 09:56:16
问题 I'm doing a project that attaches a subroutine that I wrote to a main file included by the teacher. He gave us the instructions for making our subroutine global but apparently I'm an idiot. The two asm files are in the same folder, I'm using nasm -f elf -g prt_dec.asm and ld prt_dec and then doing the same for main.asm. Here's the relevant code in the main.asm: SECTION .text ; Code section. global _start ; let loader see entry point extern prt_dec _start: mov ebx, 17 mov edx, 214123 mov edi,

Passing size as argument VS assuming shape in Fortran procedures

有些话、适合烂在心里 提交于 2019-12-19 04:03:09
问题 I'm trying to decide which one of these two options would be the best: subroutine sqtrace( Msize, Matrix, Value ) integer, intent(in) :: Msize real*8, intent(in) :: Matrix(Msize, Msize) real*8, intent(out) :: Value [instructions...] end subroutine sqtrace VS subroutine sqtrace( Matrix, Value ) real*8, intent(in) :: Matrix(:,:) real*8, intent(out) :: Value if ( size(Matrix,1) /= size(Matrix,2) ) then [error case instructions] end if [instructions...] end subroutine sqtrace I understand that

How can I smoke out undefined subroutines?

心已入冬 提交于 2019-12-18 04:33:31
问题 I want to scan a code base to identify all instances of undefined subroutines that are not presently reachable. As an example: use strict; use warnings; my $flag = 0; if ( $flag ) { undefined_sub(); } Observations When $flag evaluates to true, the following warning is emitted: Undefined subroutine &main::undefined_sub called at - line 6 I don't want to rely on warnings issued at run-time to identify undefined subroutines The strict and warnings pragmas don't help here. use strict 'subs' has

Nested subroutines and Scoping in Perl

半腔热情 提交于 2019-12-17 18:29:15
问题 I'm writing Perl for quite some time now and always discovering new things, and I just ran into something interesting that I don't have the explanation to it, nor found it over the web. sub a { sub b { print "In B\n"; } } b(); how come I can call b() from outside its scope and it works? I know its a bad practice to do it, and I dont do it, I use closured and such for these cases, but just saw that. 回答1: Subroutines are stored in a global namespace at compile time. In your example b(); is

Can we avoid creating a local variable if an optional argument is not PRESENT?

人走茶凉 提交于 2019-12-17 17:02:54
问题 I am having a problem with the PRESENT statement with Fortran 95. Currently I am using Silverfrost's Plato and their FTN95 compiler (in "Release Win32" mode). What I wanted to do is to create a subroutine SUB(a,b) , where b is an optional variable. So far so good, but the problem arises when I try to give a new value to b with if (.NOT. present(b)) b=0 . This is the code: module MOD contains subroutine SUB(a,b) implicit none integer :: a integer,optional :: b if (.NOT. present(b)) b=0 print*,

Proper use of modules in Fortran

半腔热情 提交于 2019-12-17 11:12:21
问题 I work with FORTRAN a lot, but I never had formal instruction in the proper way to write source code. I currently use modules to store global variables, but I understand you could also use them to store subroutines and functions. The codes I work with have many subroutines, as they are very large and complex. Should all functions and subroutines be in modules? If so, why? 回答1: In general the answer to your first question is Yes and I'll come to an answer to your second question in a moment.

How can I read in a variable/value which is a runtime parameter that is inside a constant list of hashes?

我与影子孤独终老i 提交于 2019-12-14 03:27:09
问题 I have tried putting the variables in the string but it reads as blank when I run the program. Here is an example of what I'm working with: use constant { #list will contain more errors ERROR_SW => { errorCode => 727, message => "Not able to ping switch $switch_ip in $timeout seconds", fatal => 1, web_page => 'http://www.errorsolution.com/727', } }; sub error_post { my ($error) = @_; print($error->{message}); } error_post(ERROR_SW); I simply want to post the error with the variable values

Is Fortran return statement obsolete?

穿精又带淫゛_ 提交于 2019-12-12 12:08:44
问题 I just want to know if the return statement in Fortran 2008 is obsolete, because it seems to be unnecessary to write it at the end of subroutines and functions. Does it have some other utility? 回答1: No, it is not obsolete. It is used to exit a subroutine and a function. Whenever you want to exit in the middle of a subroutine, you use RETURN . For example, when some error happens or similar. Using RETURN is an alternative to long if conditions like if (no_error) then a lot of code end if You