调试程序时我们通常会写一些printf()来查看运行中的值,但在工作环境中又不需要把函数中的过程变量显示出来。当print语句过多时逐行注释掉显然是费时费力的。
此时,只需在文件头使用宏定义define即可将本文件中的print语句屏蔽掉
#define printf(format, ...)
若想在本文件的某个函数中解除屏蔽,只需undef
#undef printf
墨衍会员
·
AI 创作全网分发
墨衍智能分发
本文由作者通过墨衍一键同步至各平台
1分发平台
2k累计阅读
2.1k平均单平台
已同步平台
优快云
微信公众号
微博
知乎
掘金
百家号
博客园
抖音
小红书
你的文章也可以这样分发
墨衍会员 ¥399起/年,写一次发全网
我也要 →
码龄8年
调试程序时我们通常会写一些printf()来查看运行中的值,但在工作环境中又不需要把函数中的过程变量显示出来。当print语句过多时逐行注释掉显然是费时费力的。
此时,只需在文件头使用宏定义define即可将本文件中的print语句屏蔽掉
#define printf(format, ...)
若想在本文件的某个函数中解除屏蔽,只需undef
#undef printf
全网最详细 解决戴维南定理的详细推导
替代定理,戴维南定理详细证明
C语言中一个宏关闭或者开启所有printf打印,实战必备
c.在a.h中//#define SUPPORT_LOG来关闭打印,#define SUPPORT_LOG来开启打印就行了。写c语言的时候,程序中有太多的pritnf函数,不过又不想一一去//它们怎么办?b.在其他.c文件中#include一下a.h就可以直接用LOG替代printf。d.具体为什么大家自行百度一下__VA_ARGS__和...关系。1.只需要一个宏就可以屏蔽所有printf。
大象机器人myAGV移动机器人+mechArm六轴机械臂,开源复合机器人开发与实践!
我们这章节的内容是将协作性机械臂打破距离上的限制,跟移动机器人(myAGV)相连接,实现一个案例。
一个简单的消除调试打印方法
我的工程都是在终端上运行,用C语言实现,调试时有很多打印信息,一开始也没有注意,现在准备把软件正式发布的时候,才发现这么printf屏蔽掉也是件麻烦的事情,或者用#ifdef DEBUG这个太烦,或者你查找printf并替换成//printf。这样的有点不安全,比如如果是printf与}此类括号写在一起的就会出错,当然一般是不会这么写的。我所做的是首先写一个my_printf(...)的函数,
PLC作为Modbus TCP客户端
PLC作为Modbus TCP客户端,Modbus Slave作为服务器
使用Dify搭建音频文件转文本工作流
使用Dify搭建音频文件转文本工作流
C语言之信号屏蔽和捕获(六十)
C语言之信号屏蔽和捕获(六十)
无实习经验?IT应届生简历封神思路:把校园经历写成offer收割机
摘要: IT应届生无实习经历如何打造竞争力简历?本文揭秘“无实习简历封神指南”,通过四大步骤将校园经历转化为HR认可的硬核技能: 素材挖掘:课程设计、个人项目、社团活动、竞赛证书都是隐藏的“实战经验”,用STAR法则细化成果。 技能转化:匹配岗位JD关键词,用“动词+量化结果”包装经历(如“优化查询效率30%”)。 避坑指南:避免流水账、夸大技能或堆砌无关经历,聚焦技术能力与岗位需求。 核心逻辑:HR看重潜力而非经验,用校园经历证明学习能力、问题解决能力和技术落地能力。 无实习≠无竞争力,学会“翻译”经历,
C语言scanf“屏蔽”printf使其在结束时一起输出问题的解决两种办法
两种解决办法记录一下: int a,b; ***setvbuf(stdout, NULL, _IONBF, 0);*** printf("please input a:\n "); scanf("%d",&a); fflush(stdin); printf("please input b:\n "); scanf("%d",&b); printf("年龄=%d,编号...
FPGA 学习笔记:Vitis IDE launch failed 的解决方法
FPGA 学习笔记:Vitis IDE launch failed 的解决方法
【数据可视化-77】中国历年GDP数据可视化分析:Python + Pyecharts 深度洞察(含完整数据、代码)
通过上述可视化分析,我们可以清晰地看到中国历年GDP的变化趋势和产业构成。玫瑰图展示了2024年的产业构成,地图和柱状图展示了GDP的时空分布,双轴折线图和雷达图则分别展示了GDP总量与人均GDP的变化以及各行业的GDP贡献。希望这篇文章能帮助您更好地理解和分析中国历年GDP数据。如果您有任何问题或建议,欢迎在评论区留言!🎉。
批处理中屏蔽打印信息怎么操作?
假如执行一个命令,但是不想在屏幕里看到这个命令的执行情况,可以使用"[命令]>nul"就可以屏蔽命令在屏幕上的输出,但是有的命令执行会出错,即使用了">nul"也不能屏蔽命令产生的信息,所以就在后面加" 2>nul"这个,就是"[命令]>nul+空格+2>nul",这样,不管命令是否正确的运行,都不会在屏幕看到这个命令所产生的屏幕显示了。因此,不能使用该操作符读取文件。例如,如果使用重定向操作符 >&0 启动程序,则写入句柄 1 的所有尝试操作都将失败,因为句柄 0 最初是以只读访问方式打开的。
社区版 ABAP MCP 能不能读取 SAP S/4HANA 公有云开发对象,我的判断是能试,但不能当成已被 SAP 背书的标准通道
文章摘要:当前存在多个社区项目(如mcp-abap-adt、mcp-abap-abap-adt-api等)通过包装ABAP ADT能力为MCP Server,使AI开发工具能读取ABAP对象。这些项目技术上依赖ADT HTTP API或SAP官方ADT language server,但针对SAP S/4HANA Cloud Public Edition的完整适配仍存在挑战。SAP官方已通过VS Code扩展提供ADT MCP能力,而社区方案在云环境下需遵循ABAP Cloud的严格限制,仅能访问已授权的开
Python调试升级:从print()到logging+breakpoint+structlog工程实践
在Python开发中,print()作为基础输出方式,正因缺乏上下文、不可控生命周期和缓冲风险,逐渐被更专业的诊断体系替代。现代Python调试与日志的核心在于结构化输出、可追溯上下文和分层可观测能力——logging提供等级化、格式化、可配置的日志记录;breakpoint()依托调试协议实现交互式变量洞察;structlog则将日志升维为机器可解析的JSON事件流。这些技术共同支撑起本地开发、测试验证与生产环境全链路的高效问题定位,尤其适用于微服务、异步任务和高可靠性系统。本文聚焦Python 3.7+
NTscan扫描工具
ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。
深度学习工具包 DeepLearningToolbox
深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[](https://bitdeli.com/free "Bitdeli Badge")
【C语言条件编译进阶指南】:揭秘#ifdef调试开关高效使用技巧
掌握C语言条件编译#ifdef调试开关的高效使用技巧,解决项目调试与发布切换难题。适用于多平台开发、日志输出控制等场景,通过宏定义精准控制代码段,提升编译效率与维护性,值得收藏。
廖雪峰Python教程[完整版]
廖雪峰的python教程整理的,已经排好版了,而且还是完整的,适合小白
C语言自定义打印宏函数
在调试大型项目中,打印信息分级和指出打印所在处,更方便于解决问题。查阅网上的文章并加上自己的修改,实现了个简单的宏打印函数来达到目的。宏函数实现在头文件中,加上了打印级别来控制打印是否输出,打印级别的设定需在调用的.c文件中自定义(这样做是为了能实现不同文件的打印级别能不一样,在调试指定文件或模块的问题是,能起到屏蔽其他无关代码打印的作用)。 typedef.h源码: #ifndef _TYP...
大中型超市收银系统(可直接运行)
光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开
C语言-调试程序的可变参数宏
By: Ailson Jack Date: 2021.10.29 个人博客:http://www.only2fire.com/ 本文在我博客的地址是:http://www.only2fire.com/archives/140.html,排版更好,便于学习,也可以去我博客逛逛,兴许有你想要的内容呢。 在程序的开发和调试过程中,可以使用一个宏定义来代替printf输出调试信息,等程序开发完成之后,如果不需要调试信息,直接将宏定义为空就行,这样便于随时打开和关闭调试信息。这样的调试程序的宏一般是可变参数宏,因为打
C语言调试黑科技:预编译宏开关全解析(资深工程师私藏技巧)
掌握C语言预编译宏的调试开关技巧,轻松实现代码级精准调试。适用于嵌入式开发、性能优化等场景,通过条件编译控制调试信息输出,提升开发效率与代码可维护性。方法简单却强大,资深工程师私藏实战经验,值得收藏。
c语言自定义打印函数,C语言自定义打印宏函数
在调试大型项目中,打印信息分级和指出打印所在处,更方便于解决问题。查阅网上的文章并加上自己的修改,实现了个简单的宏打印函数来达到目的。宏函数实现在头文件中,加上了打印级别来控制打印是否输出,打印级别的设定需在调用的.c文件中自定义(这样做是为了能实现不同文件的打印级别能不一样,在调试指定文件或模块的问题是,能起到屏蔽其他无关代码打印的作用)。typedef.h源码:#ifndef _TYPEDEF...
【C语言】预编译
预定义符号一共有⑤种,如下所示↓ __FILE__:表示进行编译的文件名。 __LINE__:表示文件当前的行号。 __DATE__:表示文件被编译的日期。 __TIME__:表示文件被编译的时间。 __STDC__:如果编译器遵循的是ANSIC,其中值为1,不然就是未定义。 __FUNCTION__:表示该函数所在的函数名。.......................................
VS调试技巧
VS调试介绍
Julia 源码调试完全指南:用 GDB、LLDB 与 rr 调试 Julia 运行时与编译器
本文是 Julia 语言仓库中 [debuggingtips.md](https://link.gitcode.com/i/6ee4f6a1a4e793cdb1fd6e91d46906f8) 的技术扩展指南,面向需要调试 Julia 运行时(C 代码)、编译器乃至构建(bootstrap)过程的开发者。读完本文,你将掌握如何在 GDB/LLDB 中显示任意 `jl_value_t*` 对象、插入条
mysql_print_default_my_print_defaults 显示选项文件中的选项
my_print_defaults 显示选项文件中的选项在shell脚本中,可以使用my_print_defaults程序来解析选项文件,并参见给定程序将使用哪些选项。以下示例显示当要求显示在和组中找到的选项时,my_print_defaults可能产生的输出:[client][mysql]shell>my_print_defaults client mysql--port=3306--so...
深入C语言标准库源码:从原理到实践的学习指南
C语言标准库是系统编程的核心基础,它封装了底层操作系统调用,为开发者提供了文件操作、内存管理、字符串处理等通用接口。理解其实现原理,不仅能掌握抽象背后的具体机制,还能学习到防御性编程、错误处理和性能优化的工程实践。通过阅读glibc、musl等开源实现,可以深入分析malloc/free的内存管理策略、printf的格式化解析流程等关键模块。这种源码级探究,尤其适合希望突破平台期、从语言使用者成长为驾驭者的开发者,能显著提升编写健壮、高效、可移植代码的能力。
C语言宏嵌套:预处理机制与高级应用解析
宏是C语言预处理阶段的核心特性,通过简单的文本替换实现代码生成与元编程。其工作原理遵循由外而内的展开顺序,并受递归禁止规则和参数预扫描机制约束。在工程实践中,宏嵌套常用于实现X宏代码生成、编译时断言等高级特性,但也需警惕调试困难和宏污染等问题。合理运用连接符(##)和字符串化(#)操作符,结合GCC/Visual Studio的预处理检查工具,能有效提升复杂宏系统的可维护性。在嵌入式开发和跨平台项目中,宏嵌套技术仍是实现硬件抽象层( HAL )和条件编译的关键手段。
嵌入式C固件调试全攻略:快速定位Hard Fault的7种实战方法
快速定位Hard Fault难题,提升嵌入式系统稳定性。结合C固件开发实战经验,详解7种高效调试方法,覆盖常见嵌入式场景,助你精准排查异常源头。实用技巧值得收藏。
5623
1522
423
87

被折叠的 条评论
为什么被折叠?



