New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$fscanf() strange behaviour with carriage return #685
Comments
Original Redmine Comment Verilator version used: |
Original Redmine Comment Could you make this into a test_regress/t style test (see the docs and/or edit the existing t_sys_file_basic test) and maybe attempt a fix (see fscan code in include/verilated.cpp)? |
Original Redmine Comment Any luck making a patch? |
Original Redmine Comment Hello, yes, I can give it a try. It looks like I have to modify the function _vl_vsscanf() in verilated.cpp. Maybe also displayEmit() in V3EmitC.cpp (I hope not). Regards, Frederic Requin |
Original Redmine Comment I am not able to recreate this on cygwin with either normal or DOS line endings, I will need a patch if it is to be fixed. |
Original Redmine Comment Wilson Snyder wrote:
Hello, Regards, Frederic Requin |
Original Redmine Comment I seem to get the same answer (found 31) with other simulators. Are you seeing otherwise? |
Original Redmine Comment I did not check with other simulators. I have 31 without the workaround. I started googling about the scanf() function in C and it looks like there is a limitation in the handling of carriage return. Maybe, all of this is related to C scanf()'s fault. Regards, Frederic Requin |
Original Redmine Comment Closing, if you find a test that passes on another simulator related to this please reopen or file a new bug with a testcase. |
Author Name: Frederic Requin
Original Redmine Issue: 685 from https://www.veripool.org
Original Date: 2013-10-18
This code does not work:
num = $fscanf(fh, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d\n", v_data[0], v_data[1], v_data[2], v_data[3], v_data[4], v_data[5], v_data[6], v_data[7]);
(it should extract 8 tab separated integers from a file)
The file pointer gets positionned 1 char "too far" after the call (it eats up the first char of the next line)
This one works:
num = $fscanf(fh, "%d\t%d\t%d\t%d\t%d\t%d\t%d\t%d", v_data[0], v_data[1], v_data[2], v_data[3], v_data[4], v_data[5], v_data[6], v_data[7]);
ch = $fgetc(fh); // flush carriage return (workaround)
The text file contains carriage returns coded as 0A (unix style) not 0D0A (DOS style).
I use cygwin 32-bit.
The text was updated successfully, but these errors were encountered: