函数中不写 return,返回什么值?
【生活经历分享】华师国培 华师伴学 合同都是坑 消费者付款后无法退款
和华师国培签合同需小心,合同中都是保护华师的条款,没有保护消费者的条款。
收到钱,就算你因对培训质量不满意,也不能退款。因合同消费者维权肯定十分艰难。
华师伴学的授课方式是看录制的视频,不是真人现场教学。是否是您和孩子想要的学习方式?
各位打算报名的,交费要谨慎!
其他人在小红书上发的,转:
深圳市华师国培教育科技有限公司,黑心机构,大家擦亮眼睛,别被骗了,消费欺诈,虚假承诺,签合同各种坑,收到钱了不履行承诺不退款,乱扣费,维权艰难! - 小红书
【工作要用到的技术,之前记录在云笔记中,因时间太久已经不记得出处。如果有问题请联系我,会及时配合处理】
即使在 main 函数中不写 return 0,编译器还是会默认添加个 return 0。
那其他非 main 函数也会默认添加个 return 0 吗?——不会
如果在函数内不写 return 语句,编译器则没有给 eax 寄存器更新值,那函数的返回值就不会是我们期待的样子。
————网上查到的说明。
实测返回值如下:
int main() {
// ret_val_test_int(); // ret value: 2, 2, 2, 2, 2, 2, 20, 21 - 与上一个函数的返回值无关
int ret_val_1 = ret_val_test_1(2); // ret value: 2, 2, 2, 2, 2, 2, 20, 21
int ret_val_2 = ret_val_test_2(2);
int ret_val_3 = ret_val_test_3(2);
int ret_val_4 = ret_val_test_4(2);
int ret_val_5 = ret_val_test_5();
int ret_val_6 = ret_val_test_6();
int ret_val_7 = ret_val_test_7(2);
int ret_val_8 = ret_val_test_8(2);
printf("ret value: %d, %d, %d, %d, %d, %d, %d, %d\n",ret_val_1, ret_val_2, ret_val_3,
ret_val_4, ret_val_5, ret_val_6, ret_val_7, ret_val_8);
// ret_val_test_int2(); // ret value: 2, 4, 3, 5, 5, 5, 20, 21 - 与上一个函数的返回值无关
int ret_val_10 = ret_val_test_1(2); // ret value: 2, 4, 3, 5, 5, 5, 20, 21
int ret_val_20 = ret_val_test_2(4);
int ret_val_30 = ret_val_test_3(3);
int ret_val_40 = ret_val_test_4(5);
int ret_val_50 = ret_val_test_5();
int ret_val_60 = ret_val_test_6();
int ret_val_70 = ret_val_test_7(60);
int ret_val_80 = ret_val_test_8(80);
printf("ret value: %d, %d, %d, %d, %d, %d, %d, %d\n",ret_val_10, ret_val_20, ret_val_30,
ret_val_40, ret_val_50, ret_val_60, ret_val_70, ret_val_80);
}
int ret_val_test_int(void) {
int ret = 1063;
return ret;
// return 1063;
}
int ret_val_test_int2(void) {
int ret = 928;
return ret;
// return 928;
}
// status = 2
bool ret_val_test_1(int status) {
if(0 == status) {
return true;
}
else if(1 == status) {
return false;
}
}
static bool ret_val_test_2(int status) {
if(0 == status) {
return true;
}
else if(1 == status) {
return false;
}
}
bool ret_val_test_3(int status) {
}
static bool ret_val_test_4(int status) {
}
bool ret_val_test_5(void) {
}
static bool ret_val_test_6(void) {
}
bool ret_val_test_7(int status) {
int ret = status;
ret = 20;
}
static bool ret_val_test_8(int status) {
int ret = status;
ret = 21;
}
QNX 系统下上面函数的汇编代码:
关键汇编代码(ntoaarch64-objdump -d TestProgram):
0000000000003328 <_Z16ret_val_test_intv>:
3328: d10043ff sub sp, sp, #0x10
332c: 528084e0 mov w0, #0x427 // #1063
3330: b9000fe0 str w0, [sp,#12]
3334: b9400fe0 ldr w0, [sp,#12]
3338: 910043ff add sp, sp, #0x10
333c: d65f03c0 ret
0000000000003340 <_Z17ret_val_test_int2v>:
3340: d10043ff sub sp, sp, #0x10
3344: 52807400 mov w0, #0x3a0 // #928
3348: b9000fe0 str w0, [sp,#12]
334c: b9400fe0 ldr w0, [sp,#12]
3350: 910043ff add sp, sp, #0x10
3354: d65f03c0 ret
0000000000003358 <_Z14ret_val_test_1i>:
3358: d10043ff sub sp, sp, #0x10
335c: b9000fe0 str w0, [sp,#12]
3360: b9400fe0 ldr w0, [sp,#12]
3364: 6b1f001f cmp w0, wzr
3368: 54000061 b.ne 3374 <_Z14ret_val_test_1i+0x1c>
336c: 52800020 mov w0, #0x1 // #1
3370: 14000007 b 338c <_Z14ret_val_test_1i+0x34>
3374: b9400fe0 ldr w0, [sp,#12]
3378: 7100041f cmp w0, #0x1
337c: 54000061 b.ne 3388 <_Z14ret_val_test_1i+0x30>
3380: 52800000 mov w0, #0x0 // #0
3384: 14000002 b 338c <_Z14ret_val_test_1i+0x34>
3388: 14000001 b 338c <_Z14ret_val_test_1i+0x34>
338c: 910043ff add sp, sp, #0x10
3390: d65f03c0 ret
0000000000003394 <_ZL14ret_val_test_2i>:
3394: d10043ff sub sp, sp, #0x10
3398: b9000fe0 str w0, [sp,#12]
339c: b9400fe0 ldr w0, [sp,#12]
33a0: 6b1f001f cmp w0, wzr
33a4: 54000061 b.ne 33b0 <_ZL14ret_val_test_2i+0x1c>
33a8: 52800020 mov w0, #0x1 // #1
33ac: 14000007 b 33c8 <_ZL14ret_val_test_2i+0x34>
33b0: b9400fe0 ldr w0, [sp,#12]
33b4: 7100041f cmp w0, #0x1
33b8: 54000061 b.ne 33c4 <_ZL14ret_val_test_2i+0x30>
33bc: 52800000 mov w0, #0x0 // #0
33c0: 14000002 b 33c8 <_ZL14ret_val_test_2i+0x34>
33c4: 14000001 b 33c8 <_ZL14ret_val_test_2i+0x34>
33c8: 910043ff add sp, sp, #0x10
33cc: d65f03c0 ret
00000000000033d0 <_Z14ret_val_test_3i>:
33d0: d10043ff sub sp, sp, #0x10
33d4: b9000fe0 str w0, [sp,#12]
33d8: d503201f nop
33dc: 910043ff add sp, sp, #0x10
33e0: d65f03c0 ret
00000000000033e4 <_ZL14ret_val_test_4i>:
33e4: d10043ff sub sp, sp, #0x10
33e8: b9000fe0 str w0, [sp,#12]
33ec: d503201f nop
33f0: 910043ff add sp, sp, #0x10
33f4: d65f03c0 ret
00000000000033f8 <_Z14ret_val_test_5v>:
33f8: d503201f nop
33fc: d65f03c0 ret
0000000000003400 <_ZL14ret_val_test_6v>:
3400: d503201f nop
3404: d65f03c0 ret
0000000000003408 <_Z14ret_val_test_7i>:
3408: d10083ff sub sp, sp, #0x20
340c: b9000fe0 str w0, [sp,#12]
3410: b9400fe0 ldr w0, [sp,#12]
3414: b9001fe0 str w0, [sp,#28]
3418: 52800280 mov w0, #0x14 // #20
341c: b9001fe0 str w0, [sp,#28]
3420: d503201f nop
3424: 910083ff add sp, sp, #0x20
3428: d65f03c0 ret
000000000000342c <_ZL14ret_val_test_8i>:
342c: d10083ff sub sp, sp, #0x20
3430: b9000fe0 str w0, [sp,#12]
3434: b9400fe0 ldr w0, [sp,#12]
3438: b9001fe0 str w0, [sp,#28]
343c: 528002a0 mov w0, #0x15 // #21
3440: b9001fe0 str w0, [sp,#28]
3444: d503201f nop
3448: 910083ff add sp, sp, #0x20
344c: d65f03c0 ret
0000000000003450 :
3450: d11743ff sub sp, sp, #0x5d0
3454: a9be7bfd stp x29, x30, [sp,#-32]!
3458: 910003fd mov x29, sp
345c: f9000bf3 str x19, [sp,#16]
3460: d10043ff sub sp, sp, #0x10
3464: d00000c0 adrp x0, 1d000 <__FRAME_END__+0xfde8>
3468: f947ec00 ldr x0, [x0,#4056]
346c: f9400001 ldr x1, [x0]
3470: f902f7a1 str x1, [x29,#1512]
3474: d2800001 mov x1, #0x0 // #0
3478: 528000a0 mov w0, #0x5 // #5
347c: b900dba0 str w0, [x29,#216]
3480: f0ffffe0 adrp x0, 2000
3484: 91313000 add x0, x0, #0xc4c
3488: f90073a0 str x0, [x29,#224]
348c: 97ffffa7 bl 3328 <_Z16ret_val_test_intv>
3490: 52800040 mov w0, #0x2 // #2
3494: 97ffffb1 bl 3358 <_Z14ret_val_test_1i>
3498: 53001c00 uxtb w0, w0
349c: b90037a0 str w0, [x29,#52]
34a0: 52800040 mov w0, #0x2 // #2
34a4: 97ffffbc bl 3394 <_ZL14ret_val_test_2i>
34a8: 53001c00 uxtb w0, w0
34ac: b9003ba0 str w0, [x29,#56]
34b0: 52800040 mov w0, #0x2 // #2
34b4: 97ffffc7 bl 33d0 <_Z14ret_val_test_3i>
34b8: 53001c00 uxtb w0, w0
34bc: b9003fa0 str w0, [x29,#60]
34c0: 52800040 mov w0, #0x2 // #2
34c4: 97ffffc8 bl 33e4 <_ZL14ret_val_test_4i>
34c8: 53001c00 uxtb w0, w0
34cc: b90043a0 str w0, [x29,#64]
34d0: 97ffffca bl 33f8 <_Z14ret_val_test_5v>
34d4: 53001c00 uxtb w0, w0
34d8: b90047a0 str w0, [x29,#68]
34dc: 97ffffc9 bl 3400 <_ZL14ret_val_test_6v>
34e0: 53001c00 uxtb w0, w0
34e4: b9004ba0 str w0, [x29,#72]
34e8: 52800040 mov w0, #0x2 // #2
34ec: 97ffffc7 bl 3408 <_Z14ret_val_test_7i>
34f0: 53001c00 uxtb w0, w0
34f4: b9004fa0 str w0, [x29,#76]
34f8: 52800040 mov w0, #0x2 // #2
34fc: 97ffffcc bl 342c <_ZL14ret_val_test_8i>
3500: 53001c00 uxtb w0, w0
3504: b90053a0 str w0, [x29,#80]
3508: f0000020 adrp x0, a000 <_ZN9__gnu_cxxL21__default_lock_policyE+0xcc>
350c: 91194008 add x8, x0, #0x650
3510: b94053a0 ldr w0, [x29,#80]
3514: b90003e0 str w0, [sp]
3518: b9404fa7 ldr w7, [x29,#76]
351c: b9404ba6 ldr w6, [x29,#72]
3520: b94047a5 ldr w5, [x29,#68]
3524: b94043a4 ldr w4, [x29,#64]
3528: b9403fa3 ldr w3, [x29,#60]
352c: b9403ba2 ldr w2, [x29,#56]
3530: b94037a1 ldr w1, [x29,#52]
3534: aa0803e0 mov x0, x8
3538: 97fff9ae bl 1bf0
353c: 97ffff81 bl 3340 <_Z17ret_val_test_int2v>
3540: 52800040 mov w0, #0x2 // #2
3544: 97ffff85 bl 3358 <_Z14ret_val_test_1i>
3548: 53001c00 uxtb w0, w0
354c: b90057a0 str w0, [x29,#84]
3550: 52800080 mov w0, #0x4 // #4
3554: 97ffff90 bl 3394 <_ZL14ret_val_test_2i>
3558: 53001c00 uxtb w0, w0
355c: b9005ba0 str w0, [x29,#88]
3560: 52800060 mov w0, #0x3 // #3
3564: 97ffff9b bl 33d0 <_Z14ret_val_test_3i>
3568: 53001c00 uxtb w0, w0
356c: b9005fa0 str w0, [x29,#92]
3570: 528000a0 mov w0, #0x5 // #5
3574: 97ffff9c bl 33e4 <_ZL14ret_val_test_4i>
3578: 53001c00 uxtb w0, w0
357c: b90063a0 str w0, [x29,#96]
3580: 97ffff9e bl 33f8 <_Z14ret_val_test_5v>
3584: 53001c00 uxtb w0, w0
3588: b90067a0 str w0, [x29,#100]
358c: 97ffff9d bl 3400 <_ZL14ret_val_test_6v>
3590: 53001c00 uxtb w0, w0
3594: b9006ba0 str w0, [x29,#104]
3598: 52800780 mov w0, #0x3c // #60
359c: 97ffff9b bl 3408 <_Z14ret_val_test_7i>
35a0: 53001c00 uxtb w0, w0
35a4: b9006fa0 str w0, [x29,#108]
35a8: 52800a00 mov w0, #0x50 // #80
35ac: 97ffffa0 bl 342c <_ZL14ret_val_test_8i>
35b0: 53001c00 uxtb w0, w0
35b4: b90073a0 str w0, [x29,#112]
35b8: f0000020 adrp x0, a000 <_ZN9__gnu_cxxL21__default_lock_policyE+0xcc>

浙公网安备 33010602011771号