What’s the difference btwn a command and function?

|
marcotrosi 2022-08-11 21:30:54
but functions can be written too
marcotrosi 2022-08-11 21:31:16
Fibonakki 2022-08-11 21:30:31
Where do you define this?

you wanna join the group?

Fibonakki 2022-08-11 21:31:21
Oh ok . What’s the difference btwn a command and function?
Fibonakki 2022-08-11 21:31:28
In this context
Fibonakki 2022-08-11 21:31:39
marcotrosi 2022-08-11 21:31:16
you wanna join the group?

There’s a vim group too? Ofc

Fibonakki 2022-08-11 21:32:47
Thanks @marcotrosi
Fibonakki 2022-08-11 21:33:12
armanhrshaikh 2022-08-11 21:16:16
crontab -e

Giving me option to edit my scheduled jobs but I want to redirect myjob.txt jobs inside crontab -e

Dude the guy gave a solution hello? It’s for you

marcotrosi 2022-08-11 21:33:25
Fibonakki 2022-08-11 21:31:21
Oh ok . What’s the difference btwn a command and function?

a command is mostly a one liner, and a function is sometimes bigger and can be invoked in various ways, typical script function

marcotrosi 2022-08-11 21:54:31
scenario:
I’m in Bash using vi mode, means I hit escape which puts me in vi mode
I press v which opens the current line in an actual vim instance
I can edit the line inside Vim
when I’m done with editing I quit Vim
the shell immediately executes the line

problem:
the shell immediately executes the line

wish:
it should only quit Vim and show the edited line without executing it

ideas:
I tried using :cquit hoping that the line is then not executed, but it doesnt work

question:
does anybody know if my wish can be fulfilled?

marcotrosi 2022-08-11 21:59:06
https://vi.stackexchange.com/questions/12547/vi-editing-of-bash-command-line-avoid-execution-upon-exit

vi editing of bash command line: Avoid execution upon exit?Vi and Vim Stack Exchange
I’m running bash, and my ~/.inputrc contains set editing-mode vi. This allows me to edit my command line using vi-like behaviour. And I can press v in normal mode to enter the full-fledged vi-edi…
BytesIO 2022-08-11 22:36:36
#define square(x) x*x
int main() {
printf(“%d”, square(3+4));
}

the result if 19 and I wonder why?

marcotrosi 2022-08-11 22:38:47
because you forgot the parentheses
marcotrosi 2022-08-11 22:39:04
macros are just text replacement
marcotrosi 2022-08-11 22:39:41
so basically the text is
3+4*3+4
and that is 12 + 7 = 19
marcotrosi 2022-08-11 22:40:25
if you wanna do it correctly you need

#define square(x) (x)*(x)

then the result is

(3+4)*(3+4) = 49

marcotrosi 2022-08-11 22:41:20
https://github.com/marcotrosi/C/tree/master/09_functions#function-like-macros
BytesIO 2022-08-11 22:41:30
marcotrosi 2022-08-11 22:39:41
so basically the text is
3+4*3+4
and that is 12 + 7 = 19

thanks again

marcotrosi 2022-08-11 22:42:06
BytesIO 2022-08-11 22:41:30
thanks again

welcome

BytesIO 2022-08-11 22:42:40
marcotrosi 2022-08-11 22:42:06
welcome

macros doesn’t return anything?

marcotrosi 2022-08-11 22:42:52
it’s text replacement
BytesIO 2022-08-11 22:42:59
it just substitutes code right?
marcotrosi 2022-08-11 22:43:08
yes
marcotrosi 2022-08-11 22:43:16
only the preprocessor sees them
marcotrosi 2022-08-11 22:43:21
the compiler doesnt see them
marcotrosi 2022-08-11 22:43:32
the compiler already gets the replaced text
BytesIO 2022-08-11 22:43:41
marcotrosi 2022-08-11 22:43:16
only the preprocessor sees them

take this example int a = 128/square(8) what do u think is this output

marcotrosi 2022-08-11 22:43:53
you can see it with the -E option of gcc
BytesIO 2022-08-11 22:43:54
int a = 128/8*8 right
marcotrosi 2022-08-11 22:44:07
gcc -E yourfile.c -o yourfile.p
marcotrosi 2022-08-11 22:45:11
BytesIO 2022-08-11 22:43:54
int a = 128/8*8 right

oh right, then it’s even necessary to wrap the whole thing in parentheses too

marcotrosi 2022-08-11 22:45:26
#define square(x) ((x)*(x))
marcotrosi 2022-08-11 22:45:27
like this
BytesIO 2022-08-11 22:45:45
ok so division got the precedence here
BytesIO 2022-08-11 22:46:36
so it becomes 128, wow the questions are very tricky
marcotrosi 2022-08-11 22:46:50
that’s a nice example actually, and I think I should update my tutorial which I linked
|