It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Is there any kind of file format that can't be described by BNF?
No, BNF isn't sufficient. BNF describes context-free grammars, which aren't even close to all imaginable grammars. Pretty much all programming languages, most if not all sane data serialization formats, etc. are context-free, but since you asked about theory, the answer is no. For starters, there are context-sensitive grammars, which (if the name didn't tip you off) can't be expressed with context-free grammars. A simple example would be n times a followed by n times b followed by n times c (the same n for each).
Also, grammars only describe, well, the grammar or syntax. Depending on the file format, there may be much more required for some data in that format to be valid (well-formed) - think typechecking in programming languages, for instance. You can't describe such semantics constraints with context-free grammars, or most grammars for that matter. There may be some highly complex ones that can do it in theory. They'd be correspondingly impractical, of course.
Yes. BNF only describes context free grammars. If a file contains a description of its own syntax, the rules for reading such a file couldn't be expressed in BNF. You would need a Turing machine for that. Similarly, if the decision to accept or reject a file can't be expressed by a push down automata then bnf won't work either.
BNF can't perfectly describe English syntax, for example.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
In C I have noted that pointers result in faster program execution. How is it possible, as it must fetch the pointer variable before going to the actual variable?
Pointers don't result in faster program execution. Smart algorithms result in faster program execution. Sometimes algorithms can be made smarter by using pointers in the right way. Pointers are never a magic wand to throw at problems to make the solutions faster.
Pointers are just a design paradigm though, using functional programming you do not use any pointers at all.
This is not true. The reason for faster program execution is not the availablility of pointers. It's a question of what you do with the pointers. The (possibly) faster program execution yields from the fact that no hidden functionality is introduced with C.
Take a string for example. Common implementations in other languages introduce a length field along with the string in order to keep track of the length of the string. This "bookkeeping" (although hidden from the programmer) causes extra cycles to be executed.
Another example is the fact that C does not check if the pointer you are dereferencing is valid or not. This evaluation would also cost extra cycles.
The C standard does not specify any required speed, so it doesn't make sense to attribute speed to features of C. Consider that some C implementations produce more optimal machine code than others, and it might make more sense to attribute speed to aspects of specific implementations of C1. Don't confuse implementation and specification.
1: To make a meaningful comparison of the speed of specific implementations of C, you'd probably want to mention your OS (major and minor version), your compiler (major and minor version), your CPU (model), mainboard, memory (model and configuration) and the command line arguments you used.
While I am aware every answer to the question come from people far more knowledgeable than me in C (and I am out of my league actually), IMVHO and/or limited knowledge, pointers do improve efficiency.
To answer the OP's question (and ignoring the rest about program execution and fetching):
How can pointers improve program efficiency?
By avoiding duplication of data. Although this efficiency may only be notable when dealing with user-defined variables, "structures".
Here is a nice read I found on C pointers: Why C has Pointers
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I read that a running C program can be referred to as an "instance".
Is this really correct? The word instance is usually used for OOP.
And C also has "objects" hasn't it, but it's not the same as in OOP.
An "object" in C is just something in memory like a union with some value could be called an object can't it?
An "object" in C is just something in memory, but that's also true of all computer languages.
An object in real life is a thing that physically exists. Being in memory is the closest something in a program can come to physical existence, so we apply the same term.
An instance in real life is a specific example of a generic concept. The term has similar generality in computers. When you tell the computer to run a program, it generates an instance of that program, among many potential instances of running that program. Again, nothing specific to C, this terminology usually occurs in operating systems (which manage running of programs, and define what a "program" is).
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
I was solving a practice problem on a site which states that
The purpose of this problem is to verify whether the method you are
using to read input data is sufficiently fast to handle problems
branded with the enormous Input/Output warning. You are expected to be
able to process at least 2.5MB of input data per second at runtime.
Also how do I optimize input/output routines other than printf and scanf?
It is operating system specific (because the C standard only knows about <stdio.h>). With Linux consider using low-level syscalls for efficiency, like open(2), mmap(2), read(2), pread(2), write(2). You might also want to use readahead(2). Don't forget to make I/O in rather large blocks (e.g. 128Kbytes), page aligned if possible. Read the Advanced Linux Programming book.
If restricted to standard C99 functions, use fread(3) on rather big chunks. Consider also increasing the internal buffer with setvbuf(3)
And 2.5Mbyte/sec is not very impressive. Probably, the bottleneck is the hardware, but you should be able to get perhaps 20 or 50Mbytes/sec on a standard desktop hardware. Using SSD would help a big lot.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Just curious about the term vector in programming field?
Yes, here "vector" means a one-dimensional array. This is a bit confusing because to represent a mathematical vector also uses a one-dimensional array, to store the coordinates in each of the dimensions, but this is a different usage. In this case, "vector" bring up an image of all of the elements of the array laid out in a line.
If you're referring to C, C++ or Perl (all of which use the term "argv", though Perl is the only one in which it's usually capitalized as "ARGV"): yes, it means a one-dimensional array.
The term "vector" has other uses, but they're usually pretty close to "one-dimensional array" too. For instance, the C++ standard library defines a family of vector types, which behave like extensible arrays.
(There are other uses -- for instance, "interrupt vectors" -- that have nothing to do with this. I assume you aren't interested in those.)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
Hi I'm on my internship and my company told me that I've to implement password complexity using C language. The password must be Alpha numeric (eg h#ll0). Since I'm new to C , I found some difficulty. I google "password complexity in C " but no luck there. Can someone gave me some sample or explain me how to do it programmatically.
Thanks a lot in advance
Kevin
A better Google term would be "strong password":
http://en.wikipedia.org/wiki/Password_strength
But most of the articles you will find will not be for the C language, and they will probably suggest using a regular expression.
It would probably not be too hard to write your own low-level code to do the check as others have suggested. That would save you the trouble of generating a dependency on some C-language regular expression library to use. However, there is an advantage in using a regular expression because it means that non-C programmers would have a better chance at updating the rule at a later date, and it may make errors less likely to boot. It depends on your particular situation.
(Also, if other parts of your C code need regular expressions, then linking one in might be something you're going to need to do anyway and you'd get it "for free"...)
In any case, this StackOverflow question has a link to a regex.h tutorial, and more may be added to it in the future:
C - pellucid regex.h use tutorial
You don't provide enough information. By password complexity I assume you mean password strength.
I'm not in the business of writing code for someone, but if what you're looking to do is determine whether or not a password contains both a letter and a number, is at least n characters long, etc., C has functions you can do this with. isalnum(), isdigit(), and isalpha() come to mind for testing. These all return nonzero values to indicate true.
In terms of speed, C is fast on its own but remember with these that there is no need to parse the entire password -- all you need is for the function to return a nonzero value at some point. (All of these functions parse by character; C strings are char arrays.)
http://icecube.wisc.edu/~dglo/c_class/charfunc.html This is a good little reference for character parsing functions.
It depends on how the password is encoded, you may need an ASCII character chart or a unicode character chart. For each character in the input password, categorize it into groups number, uppercase letter, lowercase letter or special characters and so on.
here are the links to the tables:
http://www.asciitable.com/
http://www.tamasoft.co.jp/en/general-info/unicode.html